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.
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.