Pyrite | Level 9

## How to properly use WHERE statement?

I am looking to make a spaghetti plot for many observations with several stipulations. I want to compare two graphs. I want to  separately consider those who have an age 18 BMI of 20-25 (“normal weight”) and those whose age 18 BMI is 25-50 (overweight). I was planning on making two graphs because I do not know how to superimpose my data or make more than one group (would love input on this if anyone knows). However, I have this code below and it's close but not quite there.

``````proc sgplot data = obese;
where ID LE 30 and age GE 18;
where also 25 >=BMI >= 20; /*I want this to be when when age is 18 but as age increases it then it can surpass these limits.*/
series x = Age y = BMI / group= ID break curvelabel;
yaxis values= (20 to 30 by 2);
xaxis values= (18 to 35 by 1 );
run;``````

I have the same code for the other graph. I have tried using the following but then it restricts it from the the people who really increase in BMI (which im interested in).

``````	proc sgplot data = obese;
where ID LE 40 and age GE 18;
where also 60 >=BMI >= 25 and Age = 18;
series x = Age y = BMI / group= ID break curvelabel;
yaxis values= (20 to 30 by 2);
xaxis values= (18 to 35 by 1 );
run;``````

Any ideas? I am open to any suggestions at all. Even if they are "Why dont you use a different graph" etc. I'm new to SAS and VERY new to sgplot.

Diamond | Level 26

## Re: How to properly use WHERE statement?

You could also modify the data set so that there is an indicator variable which shows if the person is normal weight or overweight, and the in PROC SGPLOT use the BY statement to get your two distinct plots.

You could also use a single WHERE statement rather than two separate where statements, but then you have to call PROC SGPLOT twice. But really, this isn't a job for the WHERE statement in PROC SGPLOT.

--
Paige Miller
Discussion stats