Data visualization with SAS programming

SGPLOT histogram with freq data?

Reply
Occasional Contributor
Posts: 5

SGPLOT histogram with freq data?

Hi all.


Isn't is possible to create a histogram/density in SGPLOT with data created in Proc Freq? I have data similar to this;

 

x y
1 0.10
2 0.20
3 0.30
4 0.20
5 0.15
6 0.05

So, I need six bars and a density plot - but it seems impossible for me to do it.

 

Thanks.

SAS Super FREQ
Posts: 1,079

Re: SGPLOT histogram with freq data?

If you have already computed the frequencies for each bin, you can use the GTL HistogramParm statement.  But that statement is not available in SGPLOT.  However, you can use the VBARPARM statement to create a histogram-like plot.   

 

proc sgplot data=hist;
vbarparm category=x response=y / barwidth=1;
run;

 

Hist_Vbarparm.png

 

 

 

SAS Super FREQ
Posts: 3,400

Re: SGPLOT histogram with freq data?

If you used PROC FREQ to tabulate the percentages, then presumably you are treating the data as discrete. As Sanjay points out, use a bar chart for discrete data.

 

However, if you want to use pre-tabulated data to create a histogram, you can do it but you need COUNTS rather than PERCENTAGES. PROC FREQ outputs counts, or if you know the total sample size you can create the counts, as follows;

 

data A;
N = 100;
input x y;
count = N*y;  /* create counts from percentages */
datalines;
1 0.10
2 0.20
3 0.30
4 0.20
5 0.15
6 0.05
;

proc sgplot data=A;
histogram x / freq=count binwidth=1;
density x / freq=count type=kernel;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 415 views
  • 0 likes
  • 3 in conversation