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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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