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

For a randomized normal dataset, When drawing histogram (histogram value/ scale = percent) and density (density value / type = normal scale = density) separately, their y-axes scales are different. I wanna draw a histogram and density together with histogram percentage on the left y-aix and probability density on the right y-axis. But once I have combined them, the two y-axes have the same scale with histogram percentage.

 

proc sgplot data = normal_distribution;
histogram value
/ scale = percent legendlabel = 'Histogram'
fillattrs=(color=blue) name = 'hist';
 
density value / type = normal scale = density
y2axis
lineattrs=(color=red thickness=2)
legendlabel='Probability Density'
name = 'dens';
 
keylegend 'hist' 'dens' /
linelength= 10
location = outside
position = bottom;
yaxis label = 'Histogram Percentage (%)';
y2axis label = 'Probability Density';
run;
 
kzhang1995_2-1738616382551.png

 

 kzhang1995_1-1738616365248.png

 

kzhang1995_0-1738616324736.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
quickbluefish
Barite | Level 11

Create a 2nd variable that's a copy of the first one, like this:

data normal_distribution;
do i=1 to 1000;
	value=rand('normal')*20+100;
	val2=value;   **** COPY OF VALUE ***** ;
	output;
end;
run;

proc means data=normal_distribution min p1 p5 p95 p99 max;
var value;
run;

proc sgplot data = normal_distribution;
histogram value
/ scale = percent legendlabel = 'Histogram'
fillattrs=(color=blue) name = 'hist';
 
density val2 / type = normal scale = density    /* USE VAL2 INSTEAD OF VALUE */
y2axis
lineattrs=(color=red thickness=2)
legendlabel='Probability Density'
name = 'dens';
 
keylegend 'hist' 'dens' /
linelength= 10
location = outside
position = bottom;
yaxis label = 'Histogram Percentage (%)';
y2axis label = 'Probability Density';

run;

View solution in original post

2 REPLIES 2
quickbluefish
Barite | Level 11

Create a 2nd variable that's a copy of the first one, like this:

data normal_distribution;
do i=1 to 1000;
	value=rand('normal')*20+100;
	val2=value;   **** COPY OF VALUE ***** ;
	output;
end;
run;

proc means data=normal_distribution min p1 p5 p95 p99 max;
var value;
run;

proc sgplot data = normal_distribution;
histogram value
/ scale = percent legendlabel = 'Histogram'
fillattrs=(color=blue) name = 'hist';
 
density val2 / type = normal scale = density    /* USE VAL2 INSTEAD OF VALUE */
y2axis
lineattrs=(color=red thickness=2)
legendlabel='Probability Density'
name = 'dens';
 
keylegend 'hist' 'dens' /
linelength= 10
location = outside
position = bottom;
yaxis label = 'Histogram Percentage (%)';
y2axis label = 'Probability Density';

run;
kzhang1995
Calcite | Level 5
Thanks!!! That's fantastic!!!
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1363 views
  • 4 likes
  • 2 in conversation