BookmarkSubscribeRSS Feed
siyi
Calcite | Level 5
I wanna creat one plot with 2 density lines for group A and B.
The data are like:
Age group
40 A
45 B
.
.

I used the codes:
proc sgplot data=emphysema ;
density age ;
by emphysema;
run;

The above codes gave me 2 seperate density plots. How can I combine them into one plot?
Thanks.
2 REPLIES 2
Jay54
Meteorite | Level 14
The Density statement does not support GROUP role. In cases where you have a known number of group values, you could transpose your data into multiple columns and overlay the needed plots as shown below. You don't need the BY statement.

data density;
drop i;
do i=1 to 100;
A = 20+20*ranuni(2);
B = 20+30*ranuni(3);
output;
end;
run;
/*proc print;run;*/

proc sgplot data=density;
density a / legendlabel='A';
density b / legendlabel='B';
run;
Jay54
Meteorite | Level 14
Attempting to attach the output graph.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1539 views
  • 0 likes
  • 2 in conversation