user1946152
user1946152

Reputation: 375

How to construct histograms with unequal class widths in SAS?

I am trying to create histograms in sas with the help of proc univariate in sas. But it gives me histograms with equal class widths. Suppose i want to have a histogram with first class interval from 1 to 10 and second class interval from 10 to 100. I tried using-

 proc univariate data=sasdata1.dataone;
 var sum;
 histogram sum/ midpoints=0 to 10 by 10 10 to 100 by 90 ;run;

But this does not work. What is the correct way of doing this?

Upvotes: 2

Views: 2463

Answers (1)

Joe
Joe

Reputation: 63424

You can't do it with UNIVARIATE as far as I know, but any of the SGPLOT/GPLOT/etc. procedures will work; just bin your data into a categorical variable and VBAR that variable.

If you're okay with frequencies (not percents), this would work:

data test;
set sashelp.class;
do _t = 1 to floor(ranuni(7)*20);
 age=age+floor(ranuni(7)*10);
 output;
end;
run;

proc format;
value agerange
low-12 = "Pre-Teen"
13-14 = "Early Teen"
15-18 = "Teen"
19-21 = "Young Adult"
22-high = "Adult";
quit;


ods graphics on;
ods preferences;
proc sgplot data=test;
format age agerange.;
vbar age;
run;

I believe if you need percents, you'd want to PROC FREQ or TABULATE your data first and then SGPLOT (or GPLOT) the results.

I did find a macro that can be used to create histograms with unequal endpoints. The code can be found in the NESUG 2008 proceedings

Upvotes: 2

Related Questions