Hello,
I am a total newbie in SAS and I'm writing my thesis using the NHANES data. I couldn't quite figure out how to code the physical activity classification and I would really appreciate it if anyone could help me.
One of my covariate factors is total physical activity and I have referred to the GPAQ (Global Physical Activity Questionnaire) guide from WHO. I matched it with the variables from NHANES codebook and I'm trying to classify it by level of total physical activity.
The translated variables are the following:
P2 (# of days vigorous work) = paq610
P3 (# of mins vigorous work/day) = pad615
P5 (# of days moderate work) = paq625
P6 (# of mins moderate work/day) = pad630
P8 (# of days walk or bicycle) = paq640
P9 (# of mins walk/bicycle for transportation) = pad645
P11 (# of days vigorous recreational activities) = paq655
P12 (# of mins vigorous recreational activities) = pad660
P14 (# of days moderate recreational activities) = paq675
P15 (# of mins moderate work/day) = pad675
P16 (# of mins sedentary activity) = pad680
I came up with the following code:
/*Physical Activity*/
data demo_dep9;
set demo_dep8;
/*compute total physical activity or total MET-min/week*/
totPA=(paq610*pad615*8)+(paq625*pad630*4)+(paq640*pad645*4)+(paq655*pad660*8)+(paq670*pad675*4);
if (paq610+paq655)>=3 and totPA>=150 or
(paq610+paq625+paq640+paq655+paq670)>=7 or totPA>=300
then PAlevel=1; /*High PA Level*/
if (paq610+paq655)>=3 and ((paq610*pad615)+(paq655*pad660))>=60 or
(paq625+paq640+paq670)>=5 and ((paq625*pad630)+(paq640*pad645)+(paq670*pad675))>=150 or
(paq610+paq625+paq640+paq655+paq670)>=5 and totPA>=60
then PAlevel=2; /*moderate PA level*/
else PAlevel=3; /*low PA level*/
run;
I got the following result and it seems that most of the calculations didn't go through.
I got these log results. I am quite confused as to what happened. I'd really appreciate any help or advice. Thank you!
Any calculation that involves a missing value for a variable is likely to result in a missing value for the entire line. You can reduce that to some extent by using the SUM function instead of +.
x= sum( 1,2,.) =>3
x= 1+2+. => missing
So instead of
totPA=(paq610*pad615*8)+(paq625*pad630*4)+(paq640*pad645*4)+(paq655*pad660*8)+(paq670*pad675*4);
try
totPA=sum ((paq610*pad615*8),(paq625*pad630*4),(paq640*pad645*4),(paq655*pad660*8),(paq670*pad675*4) );
And similar for all the other additions you have.
Please post LOG entries in a code box opened with the forum's {I} or "running man" icon. It is extremely hard to copy and paste from a picture and make comments of the text.
Thank you so much! It worked! I just needed to be careful about my parentheses, too. Really appreciate your time and effort answering my question. 🙂
PS. Will post on the code box for the LOG next time. 🙂 Thanks for reminding.
Hello! Was wondering if you were able to help me? I have used the same exact code for my NHANES thesis this year with a different year's data set and have edited totPA=sum (x*x), (x*x).. etc how you have advised, however, am still not getting observations for the high level of PA. The same issue here as above! What else should I revisit in the code? Parenthesis? Change all addition equations to include a "sum" statement?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.