BookmarkSubscribeRSS Feed
Pyrite | Level 9

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 );

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 );

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.


Thanks in advance.


Diamond | Level 26

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



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 2 in conversation