BookmarkSubscribeRSS Feed
KageKitsune28
Calcite | Level 5

Hello,

I am still relatively new to SAS and creating graphs/charts using SAS and could use some help determining if it is possible to create a single vertical side-by-side graph with multiple variables.  Essentially, I need to subgroup by gender,but I need the groups for  age, marital status, and income to appear on the same graph.  Is it possible to accomplish this in SAS?  Any guidance would be extremely helpful.

3 REPLIES 3
Vince28_Statcan
Quartz | Level 8

I believe the example below could help you achive your desired results:

proc sort data=sashelp.heart;

     by sex;

run;

proc freq data=sashelp.heart;

     table weight_status / out=temp2;

     by sex;

run;

data temp2;

     set temp2;

     array change _CHARACTER_;

     do over change;

          if change="" then change="Unknown";

     end;

run;

proc gchart data=sashelp.heart;

     vbar weight_status/ group=sex sumvar=count;

run;

quit;

The group= option should allow you to achieve your desired result. Thjere are definitely different ways to go about it depending on how much manipulation of your data you want to do before hand versus letting proc gchart do some of it via the statistic options. With multiple variables each having a different scale however, it is probably best to do all calculations beforehand. For instance, I would suggest you run your summary statistics on your table, then use proc transpose to get age/marital_status/income variable vertically within a new variable, use that variable and it's value column as respectively, the hbar variable and the sumvar= variable.

If you wanted sex distinction to pile vertically instead of horizontally, you can do so with the subgroup= option.

Vincent

KageKitsune28
Calcite | Level 5

Thank you for your response Vincent.  It was very helpful, and I think I may have this graph figured out now. :smileygrin:

Bill
Quartz | Level 8

From a data visualization perspective you need to be concerned about making a graph too busy or too complicated to understand.  You may well be better off to use several smaller simpler graphs on one page that present all of the stories contained in the data.

Bill

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1327 views
  • 0 likes
  • 3 in conversation