BookmarkSubscribeRSS Feed
Nikster101
Fluorite | Level 6

Hi there. I am stuck with trying to create a bar graph for 3 categorical variables; quintile (1-3, 4 and 5), nsfasyn(yes, no) and gradind(yes, no). My proc freq statement is as follows:

 

proc freq data=project;
tables gradind;
format gradind newh.;
tables quintile;
format quintile new.;
tables nsfasyn;
format nsfasyn $newn.;
tables nsfasyn*quintile*gradind/ plots=freqplot (twoway=cluster scale=percent) out=graphs5;
run;

From this code I got the following graphs:

Nikster101_0-1633337051745.png        Nikster101_1-1633337078718.png

How do I combine these graphs into one bar graph? I was thinking of using proc sgplot but nothing has work so far as it only allows for 2 variables.

5 REPLIES 5
ballardw
Super User

Please describe HOW want this combined into one graph. Do you want 4 groups of 3 bars side by side in one panel?

Stacked on top of each other? One set of values "behind" the other?

If you have an image of what you want that gives us a chance.

 

 

You will almost certainly have to use something other than Proc FREQ as that procedure has very few graphing control options and is more intended for data exploration than "camera ready" for report purposes.

Nikster101
Fluorite | Level 6
Yes, it would be 4 groups(2 x dropout, 2 x graduates) with 3 bars (quintiles) for each of the groups. So it be be one whole graph with (1 x dropout, 1 x graduate and 3 bars for each) for nsfasyn=y and then (1 x dropout, 1 x graduate and 3 bars for each) for nsfasyn=n. So it basically combine the 2 graphs I posted all in one
Reeza
Super User
You may need to create a new variable that has the two levels, NSFASYN and GRADINC into one and then use either PROC FREQ or SGPLOT.

I don't know if there's a way to specify two grouping variables in a single plot in that fashion easily. I think you can if you want to get into proc template or some of the more complex graphing options. I would definitely try the first option. But that also assumes I'm interpreting how you want them graphed correctly. Depending on exactly what you want, SGPANEL with PANELBY NSFASYN may be correct as well.
Nikster101
Fluorite | Level 6

It would be 4 groups(2 x dropout, 2 x graduates) with 3 bars (quintiles) for each of the groups. So it be be one whole graph with (1 x dropout, 1 x graduate and 3 bars for each) for nsfasyn=y and then (1 x dropout, 1 x graduate and 3 bars for each) for nsfasyn=n. So it basically combine the 2 graphs I posted all in one. I am stuck here

 

Reeza
Super User
Then I suggest creating a new variable that combines the two as I indicated earlier.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 5 replies
  • 820 views
  • 2 likes
  • 3 in conversation