BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
S_pera
Calcite | Level 5

Hi all

How can I get y scale as density for a histogram?

 

The histogram statement with proc univariate and proc sgplot support count, proportion and percentage but not density. It seems scale=density is available with proc sgplot, but it does not work with SAS On Demand for Academics.

 

I tried following codes in the PRoC Step.

 

proc univariate;
var y;
histogram y/yscale=density; 
run;
proc sgplot;
histogram y/ scale=density;
run;

 

Appreciate an answer.

 

S_pera

 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

 

To my knowledge, nor PROC UNIVARIATE, nor PROC SGPLOT have a SCALE=DENSITY on the HISTOGRAM statement.

At least not in SAS 9.4 M7 (maybe in VIYA?).

 

But PROC TEMPLATE can be used :

proc template;
  define statgraph histogram;
    begingraph;
      entrytitle "Histogram of Vehicle Weights";
      layout overlay /
        xaxisopts=(label="Vehicle Weight (LBS)")
        yaxisopts=(griddisplay=on);
        histogram weight / SCALE=DENSITY ;
      endlayout;	   
    endgraph;
  end;
run;

proc sgrender data=sashelp.cars template=histogram;
run;
/* end of program */

Koen

View solution in original post

4 REPLIES 4
Ksharp
Super User
I don't understand you want COUNT or PERCENT ?

proc univariate data=sashelp.heart;
var weight;
histogram weight/vscale=count;
histogram weight/vscale=percent;
run;
S_pera
Calcite | Level 5
I want the density.
sbxkoenk
SAS Super FREQ

Hello,

 

To my knowledge, nor PROC UNIVARIATE, nor PROC SGPLOT have a SCALE=DENSITY on the HISTOGRAM statement.

At least not in SAS 9.4 M7 (maybe in VIYA?).

 

But PROC TEMPLATE can be used :

proc template;
  define statgraph histogram;
    begingraph;
      entrytitle "Histogram of Vehicle Weights";
      layout overlay /
        xaxisopts=(label="Vehicle Weight (LBS)")
        yaxisopts=(griddisplay=on);
        histogram weight / SCALE=DENSITY ;
      endlayout;	   
    endgraph;
  end;
run;

proc sgrender data=sashelp.cars template=histogram;
run;
/* end of program */

Koen

S_pera
Calcite | Level 5

Dear Koen

Thank you very much for the solution. But I thought we could think of an easier code. Hope we will have the density option added to the histogram statement of PROC Univariate and/or PROC SGPLOT. In fact R is giving this with just

> hist(x,freq=F)

 

Anyway, the solution is highly appreciated.

 

S_pera

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 800 views
  • 4 likes
  • 3 in conversation