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

Hi,

In proc sgplot with either hbar or vbar statement, how to bring information from two variables to one bar.  For eg. var1=5 and var2=10.  Other obs could be var1=2 and var2=5.  The plot should show one bar for each obs and each representaive bar should show informaion from both var1 (red) and var2 (blue).  The group won't work here. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If you want the bars stacked change GROUPDISPLAY from CLUSTER to STACK. 

View solution in original post

9 REPLIES 9
Ram_SAS
Obsidian | Level 7
Basically need to show two 'response' values into one bar with different color.
Reeza
Super User

You'll need to restructure you data into how SAS expects it to be for a stacked bar chart. 

This means combining the variables and included a new variable to denote the source/group.

Ram_SAS
Obsidian | Level 7

You mean create a new variable by adding var1+var2.  But in the vbar statement, what will be go in response=?? and group= combined?? groupdisplay=stack?  Thanks.

Reeza
Super User

If you want sample code post sample data.

Ram_SAS
Obsidian | Level 7
Here is a sample data. Need to show var1 and var2 of each customer in the same bar.

data fitness;
input cus_id country $ var1 var2;
datalines;
102 Can 3.73 11.2
105 USA 20.3 9.1
123 USA 4.6 16.4
156 Can 8.1 0.3
177 USA 0.5 13.4
;
run;
Cynthia_sas
SAS Super FREQ

Hi:

  Restructuring the data will get you want you want. You just need to make 2 observations for every observation in the input data.

cynthia

sgplot_vbar.png

Reeza
Super User

If you want the bars stacked change GROUPDISPLAY from CLUSTER to STACK. 

Ram_SAS
Obsidian | Level 7

Thanks Reeza and Cynthia..!  Did not get the restructuing part, it is clear now.

Reeza
Super User

The correct answer should be Cynthia's post. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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