Help using Base SAS procedures

graphically comparing 2 distributions

Reply
Super Contributor
Posts: 395

graphically comparing 2 distributions

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.

SAS Super FREQ
Posts: 8,743

Re: graphically comparing 2 distributions

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;

Trusted Advisor
Posts: 2,113

Re: graphically comparing 2 distributions

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

Ask a Question
Discussion stats
  • 2 replies
  • 225 views
  • 0 likes
  • 3 in conversation