Data visualization with SAS programming

how can I overlay two density plots?

Reply
N/A
Posts: 1

how can I overlay two density plots?

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.
SAS Super FREQ
Posts: 1,044

Re: how can I overlay two density plots?

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;
SAS Super FREQ
Posts: 1,044

Re: how can I overlay two density plots?

Attempting to attach the output graph.
Post a Question
Discussion Stats
  • 2 replies
  • 504 views
  • 0 likes
  • 2 in conversation