Nerve impingement, hip arthritis pain can be worse while sitting.
Often the cause of muscle spasm may not be detected.
Deficiency of calcium, magnesium, potassium, sodium- vitamins, dehydration etc. are the major factors.
Poor circulation or nerve involvement like nerve impingement, dystonia, MS etc. also can cause muscle spasm.
It can also be present in diabetes, hypothyroid state.
You may try some home measures till you consult doctor.
Regular exercise or a walk daily to keep you active.
Stretching or gentle massage are helpful in muscle spasm.
Tylenol or motrin can be taken.
Please take plenty of fluid, fruits, vegetables.
Avoid coffee, alcohol, tobacco etc, if you take any.