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: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 680 views
  • 4 likes
  • 3 in conversation