Hello everyone,
I would like to know how I can plot the density plot comparing the first and last decile group of a quantitive variable.
Thanks in advance
I don't understand. Compare first decile to last decile based on what criteria of comparison? I would think they are different by definition.
Hello,
Start here:
proc rank data=sashelp.heart(keep=height) out=work.heart_deciles groups=10;
VAR height;
RANKS height_decile;
run;
proc sort data=work.heart_deciles;
by height_decile;
where height_decile IN (0,9);
run;
proc sgplot data=work.heart_deciles;
title "Height Distribution per decile";
by height_decile;
histogram height;
density height;
density height / type=kernel;
keylegend / location=inside position=topright;
run;
title;
/* end of program */
With PROC SGPANEL, you can have both density plots in one graphical file (one "container").
Cheers,
Koen
Usually, you would compare the distribution of a variable for groups defined by some other variable:
proc rank data=sashelp.heart(keep=weight cholesterol) out=work.heart_deciles groups=10;
VAR weight;
RANKS weight_decile;
run;
proc sort data=work.heart_deciles;
by weight_decile;
run;
proc sgpanel data=work.heart_deciles;
title "Cholesterol Distribution per Decile";
where weight_decile in (0,9);
panelby weight_decile / columns=1;
histogram Cholesterol;
density Cholesterol / type=kernel;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.