03-06-2016 01:37 PM
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.
03-06-2016 01:54 PM
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;
03-06-2016 03:40 PM
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;