BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

How can I compare 2 distributions graphically.. I have 2 different datasets of the same variable and I'd like to compare that variable in Set1 with the same variable in Set2.

Thanks.

2 REPLIES 2
Cynthia_sas
Diamond | Level 26

Hi:

  If you have SAS 9.2 or higher, you can use PROC SGPANEL to give you a nice graph. For example, in the program below, I use SASHELP.CLASS and then make a "fake" dataset called WORK.CLASS2 and make 1 new dataset called WORK.BOTHCLASSES with a DATAFILE variable as an identifier. Then I use PROC SGPANEL with a PANELBY statement to show two histograms for AGE side by side.

cynthia

data class2;

  set sashelp.class;

  ** create a different age value ;

  ** for second dataset;

  age=age+2;

run;

   

data bothclasses(keep=name age datafile);

  ** now make a variable to represent the datafile;

  set sashelp.class(in=inone)

      work.class2(in=intwo);

  if inone = 1 then datafile='SASHELP.CLASS';

  if intwo = 1 then datafile='WORK.CLASS2';

run;

  

ods listing close;

ods pdf file='c:\temp\panel_hist.pdf';

proc sgpanel data=bothclasses;

  title 'Compare Two Histograms';

  ** use PANELBY to show each data sets info;

  ** in a separate panel using HISTOGRAM statement;

  panelby datafile;

  histogram age / binstart=11 ;

  density age;

  density age / type=kernel;

  colaxis values=(11 to 18 by 1);

run;

ods pdf close;

Doc_Duke
Rhodochrosite | Level 12

Check out the ODS graphics in PROC NPAR1WAY in SAS 9.3.  It may have what you are looking for.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Update

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1940 views
  • 0 likes
  • 3 in conversation