Hi everyone,
First of all, I am using SAS 9.4 on SAS EG 7.1.
I am trying to plot a stacked bar chart and a line chart on the same plot(figure) instead of plotting them in two separate figures. For the stacked bar chart I am using a "GROUP" statement because I have 5 different bins to be stacked on top of each other. For the line chart however I do not need a group since I would like to plot the mean for the overall population without partitions. In this case I get a group error stating that if I use group in vbar statement I must use group also in vline. Could anyone have any idea on how to overcome this problem? Below I put my code and result I get. Thank you so much..
In this case, you will want to use the following steps:
1. Use PROC SUMMARY or PROC MEANS to precompute the bar chart data.
2. Use PROC SUMMARY or PROC MEANS to precompute the line chart data. Be sure to use different variable names from the bar chart data in the output data sset.
3. Merge the two data sets together.
4. Instead of using VBAR and VLINE, use the VBARPARM and SERIES statements. Your code will look something like the following:
proc sgplot data=merged;
vbarparm category=&TIME_GROUP response=freq_values / group=&COLUMN.binned seglabel ...;
series x=&TIME_GROUP_2 y=mean_values;
...
run;
Let me know if you have any issues with this approach.
Thanks!
Dan
You could create a value of the mean &COLUMN.binned, such that the value is the same for each value of the GROUP= variable. Then when you use the GROUP= option in the VLINE statement, all the lines plot on top of each other, making it look like one line.
Or maybe @DanH_sas has a better idea.
Can you clarify what this means (best would be some example data): "I would like to plot the mean for the overall population without partitions".
As in what is the "overall population"?
I am having a hard time envisioning what sort of line you envision by taking the Mean of the group variable (the Response=) as your code requests.
In this case, you will want to use the following steps:
1. Use PROC SUMMARY or PROC MEANS to precompute the bar chart data.
2. Use PROC SUMMARY or PROC MEANS to precompute the line chart data. Be sure to use different variable names from the bar chart data in the output data sset.
3. Merge the two data sets together.
4. Instead of using VBAR and VLINE, use the VBARPARM and SERIES statements. Your code will look something like the following:
proc sgplot data=merged;
vbarparm category=&TIME_GROUP response=freq_values / group=&COLUMN.binned seglabel ...;
series x=&TIME_GROUP_2 y=mean_values;
...
run;
Let me know if you have any issues with this approach.
Thanks!
Dan
Thank you so much. It worked like magic.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.