Hello All,
Using gbarline procedure, can I group the bars or give give color to a group of bars?
I couldn't get any option to group the bars(say by year)... so thought of coloring the bars by year using the PATTERNID option. But patternid requires the use of BY statement.
By using BY statement i can color & group them but then a separate graph gets created for each value of BY variable which I dont want...
proc gbarline data=temp;
bar date1 / discrete sumvar=y1v patternid=by;
plot / sumvar=y2v axis=axis2;
by year;
run;
quit;
Can somebody pls let me know if its possible to group bars using gbarline?
You could use a subgroup = your_variable for the bar plot.; but first you need to sort your data by that group variable.
Here is an example using the SASHELP.CLASS data set.
proc sort data= sashelp.class out = temp;by sex;
proc gbarline data = temp;
bar name / discrete sumvar = age subgroup = sex;
plot / sumvar = weight ;
run;
quit;
Best of luck.
Anca.
Thanks Anca, this works ...that is I get different colors for different groups....
I had seen subgroup option creating stacked bars...so thought it wont be used to create grouped bars/or color them.. Thanks once again,Anca!!
Also , if I want to display only the subgroup values below the X-axis or M-axis then is that possible...
Like suppose, each bar represents a month ... Jan, feb, mar....
But i dont want to display month or monYY below each bar.... I only want to display year 2001 , 2002 below a set/group of bars for a particular year....??
DATE1 | Y1V | Y2V | YEAR |
1-Jan-08 | 1001 | 2 | 2008 |
1-Feb-08 | 1002 | 3 | 2008 |
1-Mar-08 | 1003 | 4 | 2008 |
1-Apr-08 | 1004 | 5 | 2008 |
1-May-08 | 1005 | 6 | 2008 |
1-Jun-08 | 1006 | 7 | 2008 |
1-Jul-08 | 1007 | 8 | 2008 |
1-Aug-08 | 1008 | 9 | 2008 |
1-Sep-08 | 1009 | 10 | 2008 |
1-Oct-08 | 1010 | 11 | 2008 |
1-Nov-08 | 1011 | 12 | 2008 |
1-Dec-08 | 1012 | 13 | 2008 |
1-Jan-09 | 1013 | 14 | 2009 |
1-Feb-09 | 1014 | 15 | 2009 |
1-Mar-09 | 1015 | 16 | 2009 |
1-Apr-09 | 1016 | 17 | 2009 |
1-May-09 | 1017 | 18 | 2009 |
1-Jun-09 | 1018 | 19 | 2009 |
1-Jul-09 | 1019 | 20 | 2009 |
1-Aug-09 | 1020 | 21 | 2009 |
1-Sep-09 | 1021 | 22 | 2009 |
1-Oct-09 | 1022 | 23 | 2009 |
1-Nov-09 | 1023 | 24 | 2009 |
1-Dec-09 | 1024 | 25 | 2009 |
1-Jan-10 | 1025 | 26 | 2010 |
1-Feb-10 | 1026 | 27 | 2010 |
1-Mar-10 | 1027 | 28 | 2010 |
1-Apr-10 | 1028 | 29 | 2010 |
1-May-10 | 1029 | 30 | 2010 |
1-Jun-10 | 1030 | 31 | 2010 |
1-Jul-10 | 1031 | 32 | 2010 |
1-Aug-10 | 1032 | 33 | 2010 |
1-Sep-10 | 1033 | 34 | 2010 |
1-Oct-10 | 1034 | 35 | 2010 |
1-Nov-10 | 1035 | 36 | 2010 |
1-Dec-10 | 1036 | 37 | 2010 |
proc gbarline data=temp;
bar date1 / discrete sumvar=y1v subgroup=year;
plot / sumvar=y2v axis=axis2;
run;
quit;
Sure, you could display only the value for the subgroup.
One dirty way to do that (given that you have exactly 12 months of data in each year) would be to assign blank values to the tick marks, and the 2008, 2009 or 2010 value for some of the tick marks.
See below:
goptions reset = all;
axis1 v = ("" "" "" "" "" "2008" "" "" "" "" "" ""
"" "" "" "" "" "2009" "" "" "" "" "" ""
"" "" "" "" "" "2010" "" "" "" "" "" "");
proc gbarline data=temp;
bar date1 / discrete sumvar=y1v subgroup=year maxis = axis1;
plot / sumvar=y2v;
run;quit;
Thanks Anca.... This is also helpful
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 25. Read more here about why you should contribute and what is in it for you!
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.