BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CIG21
Fluorite | Level 6

Hello everyone!

 

I'm having a dataset in SAS which looks similar to the below picture one and I am trying to create the same graph in SAS with proc sgplot and vbar, however, I struggle to be able to choose the two columns for the bars. With the response and group command I can only choose one of each...

 

I also tried it with two vbars in one proc sgplot and the response being for one active cases and for the other passive cases, however, that did not work properly.

 

Is there any way how I can achieve creating the below graph? Or do I have to change my dataset first, if yes, how? I'd prefer to stay with proc sgplot, if possible. Any help is greatly appreciated 🙂

Screenshot 2020-10-16 095535.png

1 ACCEPTED SOLUTION

Accepted Solutions
CurtisMackWSIPP
Lapis Lazuli | Level 10

VBAR wants the data structured differently.  The stack value needs to be a variable.  Something like this.

 

data have;
  infile cards dsd;
  input weekday $ var1 var2;
  format datetime1 datetime2 datetime20.;
cards; 
Monday,23,12
Tuesday,21,4
Wednesday,4,5
Thursday,5,29
Friday,8,9
;
run;

data want;
  set have;
  actual = var1; cat="cat1"; output;
  actual = var2; cat="cat2"; output;
run;

proc sgplot data=want;
  title 'Actual Sales by Day';
  vbar weekday / response=actual group=cat stat=sum;
  xaxis display=(nolabel);
  yaxis grid  label='Sales';
  run;

View solution in original post

2 REPLIES 2
CurtisMackWSIPP
Lapis Lazuli | Level 10

VBAR wants the data structured differently.  The stack value needs to be a variable.  Something like this.

 

data have;
  infile cards dsd;
  input weekday $ var1 var2;
  format datetime1 datetime2 datetime20.;
cards; 
Monday,23,12
Tuesday,21,4
Wednesday,4,5
Thursday,5,29
Friday,8,9
;
run;

data want;
  set have;
  actual = var1; cat="cat1"; output;
  actual = var2; cat="cat2"; output;
run;

proc sgplot data=want;
  title 'Actual Sales by Day';
  vbar weekday / response=actual group=cat stat=sum;
  xaxis display=(nolabel);
  yaxis grid  label='Sales';
  run;
CIG21
Fluorite | Level 6
Brilliant, exactly what I needed. Thank you!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 2561 views
  • 2 likes
  • 2 in conversation