Help using Base SAS procedures

Is it possible to have multiple variables on one vbar graph.

Reply
Occasional Contributor
Posts: 7

Is it possible to have multiple variables on one vbar graph.

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.

Super Contributor
Posts: 339

Re: Is it possible to have multiple variables on one vbar graph.

Posted in reply to KageKitsune28

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

Occasional Contributor
Posts: 7

Re: Is it possible to have multiple variables on one vbar graph.

Posted in reply to Vince28_Statcan

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

Super Contributor
Posts: 291

Re: Is it possible to have multiple variables on one vbar graph.

Posted in reply to KageKitsune28

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

Ask a Question
Discussion stats
  • 3 replies
  • 214 views
  • 0 likes
  • 3 in conversation