BookmarkSubscribeRSS Feed
Steffenhaldrup
Fluorite | Level 6

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.

2 REPLIES 2
Jay54
Meteorite | Level 14

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

 

 

 

Rick_SAS
SAS Super FREQ

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2894 views
  • 0 likes
  • 3 in conversation