SAS Procedures

Help using Base SAS procedures
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1790 views
  • 0 likes
  • 3 in conversation