BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Assume I have a table with the following column headings: Year, Value 1, Value 2, and Group. I need a Grouped/Vertical Stacked bar chart which shows 2 bars: year (1994, 1995) for 2 Groups (0,1) and in these bars Value 1 builds the upper limit of the bar (e.g. year 1994; Value1 = 10) and Value2 should be a fration of this bar (e.g Value2 = 5 which is half of Value1 = 10). What do I click where in the Task Roles? Column to chart= Year, Group bars by = ???, Stack = Value2, Sum of = Value1, group charts by = Group. CHEERS!
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi!
If your data -currently- looks like this:
Year Grp Value1 Value2
1994 0 200 100
1994 1 140 70
1995 0 150 75
1995 1 160 80

You would need to tranform your data in order to create the kind of chart you want (because SAS/Graph limits you to just 1 "SUM OF" variable). So, IF you transformed your data to look like this:

Year Grp Type Num
1994 0 Value1 100
1994 0 Value2 100
1994 1 Value1 70
1994 1 Value2 70
1995 0 Value1 75
1995 0 Value2 75
1995 1 Value1 80
1995 1 Value2 80

Then EG and SAS/Graph will give you the output you want. Note, that if Value 1 is the total height of the bar, then you have to subtract
Value 2 from Value 1 in the transformed data because SAS/Graph will want to sum on
the variable for your "sum of". In this way, SAS/Graph takes care of the bar height
for you. At any rate, the correct click path would be (assumes you have already created the transformed data table):

Start new project to transform data OR
Add transformed data to project
Highlight transformed data table in project
Graph --> Bar Chart --> Grouped/Stacked Vertical Bar
Task Roles --> Column to Chart = Year
Task Roles --> Group bars by = Grp
Task Roles --> Stack = Type
Task Roles --> Sum of = Num
Appearance --> Bars --> click on the box "Specify number of bars" and then make sure that the top radio button is checked (One bar for each unique data value).
Then select --> RUN to create the graph


The issue with the data as you describe it, is that you have 2 numeric variables, Value1 and Value2 but, SAS/Graph only allows you to have 1 numeric variable for the "sum of" role. This means that you need a "Type" variable which is set to either value1 or value2 and then you need only 1 numeric variable, but the combination of Year, Grp and Type make sure that SAS/Graph uses the value for the right piece of the bar chart.

If you contact Tech Support, they can help you figure out how to transpose your data to be in the right form for SAS/Graph. You could either use PROC TRANSPOSE or you could use a DATA STEP program. Since you may need to subtract Value2 from Value1 in order to adjust Value1, that points to a DATA STEP program (which you would put into a CODE NODE in EG). Of course, if you have entered the data points into EG by typing them, then you could just readjust your input. Tech Support is really your best bet to help you with data manipulation issues in EG (or anywhere else, for that matter).

cynthia
deleted_user
Not applicable
Awesome, thanks heaps Cynthia!
A

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 771 views
  • 0 likes
  • 2 in conversation