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

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. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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; 

ChrisNZ_0-1627276355352.png

 

 

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

So one X axis showing 2 variables side by side?

ChuksManuel
Pyrite | Level 9

Yes!

ChrisNZ
Tourmaline | Level 20
ChuksManuel
Pyrite | Level 9

Y is a percentage.

ChrisNZ
Tourmaline | Level 20

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; 

ChrisNZ_0-1627276355352.png

 

 

ChuksManuel
Pyrite | Level 9
Thanks!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 1281 views
  • 0 likes
  • 2 in conversation