BookmarkSubscribeRSS Feed
abigailpuno
Calcite | Level 5

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. gpaq.PNG

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. 

 

PA result.PNG

 

 

log results.PNG

 

I got these log results. I am quite confused as to what happened. I'd really appreciate any help or advice. Thank you!

 

3 REPLIES 3
ballardw
Super User

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.

abigailpuno
Calcite | Level 5

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. 

indnahc
Calcite | Level 5

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? 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2688 views
  • 1 like
  • 3 in conversation