BookmarkSubscribeRSS Feed
mantubiradar19
Quartz | Level 8

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

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I don't understand. Compare first decile to last decile based on what criteria of comparison? I would think they are different by definition.

--
Paige Miller
sbxkoenk
SAS Super FREQ

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

mantubiradar19
Quartz | Level 8
Hi Koen, many thanks. Let me try this code.
PGStats
Opal | Level 21

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;

PGStats_0-1629596293620.png

 

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 1418 views
  • 1 like
  • 4 in conversation