I am trying create a graph that shows the row percent only for 2 groups and within the graph show 2-3 variables.. How do I do this?
I created an example in Excel which is attached as an image. I am hoping to do this in SAS, since I have a lot of graphs to create and also want to avoid copying and pasting numbers (so don't want any human error).
I have the raw data, so I will need to use proc freq to compute the percentages.
Okay, here is an example then. I agree with RW9 too, you need to drop the No data before you plot the graph.
data test;
input var$ group$ response$ result;
cards;
var1 group1 yes 0.7
var1 group2 yes 0.75
var1 group1 no 0.3
var1 group2 no 0.25
var2 group1 yes 0.35
var2 group2 yes 0.2
var2 group1 no 0.65
var2 group2 no 0.8
;
run;
proc sgpanel data = test;
where response = "yes";
panelby var;
vbar group / response = result group = response stat= mean;
run;
Hi,
What version of SAS do you have please? Can you provide the raw data or the data of the percentages please?
Thanks.
SAS 9.2, I can't provide the raw dataset.
I am looking for the general approach I should use so I can code this myself.
Okay, here is an example then. I agree with RW9 too, you need to drop the No data before you plot the graph.
data test;
input var$ group$ response$ result;
cards;
var1 group1 yes 0.7
var1 group2 yes 0.75
var1 group1 no 0.3
var1 group2 no 0.25
var2 group1 yes 0.35
var2 group2 yes 0.2
var2 group1 no 0.65
var2 group2 no 0.8
;
run;
proc sgpanel data = test;
where response = "yes";
panelby var;
vbar group / response = result group = response stat= mean;
run;
Well, the simplest way would be to have a datastep before it which drops the No data, then its just a barchart by group.
Alternatively, a stacked barchart, with the no group given color white would also work. You can find many examples of all types of graphs here:
http://blogs.sas.com/content/graphicallyspeaking/?s=stacked
I have filtered for stacked, but there are many examples.
If I drop the No data, wouldn't the % be impacted?
Since I want the percentages of "Yes" within the variable for that group...
Is there a way I can make SAS create a bar graph of just numbers? I am thinking if I can use proc freq with an out= option and keep only the percentage of yes within that dataset and graph that?
You can calculate the percentages using all the data, and then drop the "No data" before you produce the barchart.
So what does your data look like, I assumed from what you had posted you already had percentages, but from the below, you seem to be calculating percentage from data. Can you clarify what your data looks like, if you already have the percentages then @djrisks solution should work.
So my data looks something like this (sample data, not actual). where 1=yes and 2=no and then a group variable 1/2. All these have formats (so var, yes/no and group with group names)
So in this case, I want to calculate the row percentage of each variable for each group and then graph only the %yes
The percentage that I have calculated in my excel graph example would be from the proc freq results. I have about 200 vars, of course now 200 variables would be on one graph). So I am wondering is there a way to streamline/automate this?
@Tpham The percents are not impacted because there is only 1 value for each column and if you take the mean or sum of a single number the value is the single number so it graphs the way you expect.
Essentially you're pre-calculating your values and using the above logic to produce your graph.
The example from @djrisks demonstrates this, though you'll need to customize the plot.
What about this one - it uses GCHART but allows for groups and subgroups.
http://robslink.com/SAS/democd7/col1.htm
http://robslink.com/SAS/democd7/col1.sas
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.