Data visualization with SAS programming

sgplot with Multiple variables on vbar

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

sgplot with Multiple variables on vbar

proc sgplot data=pande_app4_w_bad;

vbar Selskapspolicy / response=Bad_6m stat=mean DATALABEL
barwidth=0.6 fillattrs=graphdata1 ;
  yaxis grid display=(nolabel);
  xaxis display=(nolabel);


vbar Selskapspolicy / response=Bad_12m stat=mean DATALABEL
barwidth=0.4 fillattrs=graphdata2 ;
  yaxis grid display=(nolabel);
  xaxis display=(nolabel);
run;

image.png

 

I am not getting this as neat as I want to side by side...Anyone?


Accepted Solutions
Solution
‎08-23-2017 10:44 AM
SAS Super FREQ
Posts: 1,139

Re: sgplot with Multiple variables on vbar

If you want the blue and red bars to be placed side by side, you have two options.

  1. Use DISCRETEOFFSET.  Reduce both bar widths, and use discreteoffset=-0.2 with one and discreteoffset=+0.2 with other.  You can adjust the widths and offsets to suit.
  2. Change your data set from 2 response columns to one response column with a classifier.  Then you can use the GROUP option with GROUPDISPLAY=CLUSTER to get side by side bars.  This way is more scalable and preferable.

View solution in original post


All Replies
Solution
‎08-23-2017 10:44 AM
SAS Super FREQ
Posts: 1,139

Re: sgplot with Multiple variables on vbar

If you want the blue and red bars to be placed side by side, you have two options.

  1. Use DISCRETEOFFSET.  Reduce both bar widths, and use discreteoffset=-0.2 with one and discreteoffset=+0.2 with other.  You can adjust the widths and offsets to suit.
  2. Change your data set from 2 response columns to one response column with a classifier.  Then you can use the GROUP option with GROUPDISPLAY=CLUSTER to get side by side bars.  This way is more scalable and preferable.
Contributor
Posts: 40

Re: sgplot with Multiple variables on vbar

Yeah I want to use the Group option, but found it hard to implement as my data is of the type

 

reponsecolumn1 responsecolumn2
1 1
0 1
0 0
1 0

 

How do I get it to a one response column and a classifier?

SAS Super FREQ
Posts: 1,139

Re: sgplot with Multiple variables on vbar

[ Edited ]

You can use PROC TRANSPOSE.  if you have data set "Response" with Cat, Response1 and Response2, you can use the following.  The response column names will show up as group values.

 

proc transpose data=response out=groups;
  by cat;
run;

 

For a simple case like yours, I use a simple data step:

 

data groups;
  keep Cat Group Response;
  set response;
  Group=1; Response=response1; output;
  Group=2; Response=response2; output;
run;

Here is an article by Rick on this topic. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 164 views
  • 0 likes
  • 2 in conversation