BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
chester2018
Obsidian | Level 7

Hi everyone!

I'm creating a new variable, and I'm having issues with the IF-THEN-ELSE statements. For my variable, I would like to calculate the weekly minutes only if that participant has a MET value (either Moderate or Vigorous). Therefore, people without a MET value won't get the calculation.

 

So, participants may or may not have a MET value (indicated by Vigorous or Moderate). If they do have a MET value, I would like to calculate their average weekly activity (min_week = ((a*b*7)/30)). So, if someone with a MET value =., I don't want to give them an average weekly activity. The attached data is what I don't want. I don't want the highlighted portions because the participants don't have a METS value.

Hope I made some sense

data exercise.writeinsMETS;
	set exercise.writeinsMETS;
	if METS="Vigorous" or METS = "Moderate";
	else if writein38_min_week=((v5qa38a*v5qa38b*7)/30);
	else if writein39_min_week=((v5qa39a*v5qa39b*7)/30);
	else if writein40_min_week=((v5qa40a*v5qa40b*7)/30);
	else max(writein38_min_week, writein39_min_week,writein40_min_week) = .;
run;

sas.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Here is your IF statement in your own words:

 

If they do have a MET value, I would like to calculate their average weekly activity (min_week = ((a*b*7)/30)). So, if someone with a MET value =., I don't want to give them an average weekly activity.

 

What you have in your code bears little resemblance to the above.

 

To put this into something close to SAS code, this is what you want, where I leave blanks for you to fill in as a homework assignment,

 

if not missing(_________) then min_week=_____________; else min_week=________;

 

Explanation

 

if not missing(________) /* you said if they do have a MET value */
then min_week=_________;  /* you said calculate their average weekly activity */
else min_week=__________; /* you said you don't want them to have an average weekly activity */

 

By the way, it isn't really helpful to have variables in your code that are not mentioned in your explanation, we don't know what they and we don't know how to use them properly.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Here is your IF statement in your own words:

 

If they do have a MET value, I would like to calculate their average weekly activity (min_week = ((a*b*7)/30)). So, if someone with a MET value =., I don't want to give them an average weekly activity.

 

What you have in your code bears little resemblance to the above.

 

To put this into something close to SAS code, this is what you want, where I leave blanks for you to fill in as a homework assignment,

 

if not missing(_________) then min_week=_____________; else min_week=________;

 

Explanation

 

if not missing(________) /* you said if they do have a MET value */
then min_week=_________;  /* you said calculate their average weekly activity */
else min_week=__________; /* you said you don't want them to have an average weekly activity */

 

By the way, it isn't really helpful to have variables in your code that are not mentioned in your explanation, we don't know what they and we don't know how to use them properly.

--
Paige Miller
chester2018
Obsidian | Level 7

Thank you so much! I didn't realize my code and variables were not correctly presenteded!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 578 views
  • 0 likes
  • 2 in conversation