Is it possible to print two histograms on a graph using proc sgplot?
My code has been:
proc sgplot data=me;
where num_days=:'Days 100 - 200';
histogram obese/ fillattrs=(color=pink) nbins=5 showbins;
run;The above code me just one histogram. How do I add a histogram of a second variable "sex" alongside that of "obese" on the same graph.
Here is a (very ugly) way. There might be better ways.
data PLOT;
set SASHELP.CLASS;
length X $10;
X=cats(AGE); PCT=AGE/2; output;
X=SEX ; PCT + 3; output;
if _N_=1 then do; X='A'; PCT=0; output; end;
run;
proc format ; value $xaxis 'A '=' ';
ods graphics on / width=1000px height=400px;
proc sgplot data=PLOT;
vbar X / response=PCT attrid=X;
format X $xaxis.;
xaxis label= "%sysfunc(repeat(%str( ),50)) Age %sysfunc(repeat(%str( ),120)) Sex" ;
run;
So one X axis showing 2 variables side by side?
Yes!
What does the Y axis look like?
Y is a percentage.
Here is a (very ugly) way. There might be better ways.
data PLOT;
set SASHELP.CLASS;
length X $10;
X=cats(AGE); PCT=AGE/2; output;
X=SEX ; PCT + 3; output;
if _N_=1 then do; X='A'; PCT=0; output; end;
run;
proc format ; value $xaxis 'A '=' ';
ods graphics on / width=1000px height=400px;
proc sgplot data=PLOT;
vbar X / response=PCT attrid=X;
format X $xaxis.;
xaxis label= "%sysfunc(repeat(%str( ),50)) Age %sysfunc(repeat(%str( ),120)) Sex" ;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.