Hi....I am trying to produce graphs for each year using proc sgplot. I tried to used the By statement but that doesn't seem to work. Any suggestion how it can be done. Also, does proc sgplot allow to plot a line on the second y axis? Thanks.
proc sgplot data=have; vbarparm category=Geo response=University / discreteoffset=-0.17 barwidth=0.3; vbarparm category=Geo response=College / discreteoffset=0.17 barwidth=0.3; yaxis valuesdisplay=(0 to 100 by 10) label="Percentage (%) " labelattrs=(size=13 ); xaxis label="Department" labelattrs=(size=13) fitpolicy=rotatethin valuesrotate=vertical; run;
You need to sort the dataset by proc sort and use the by statement in proc sgplot as below
proc sort data=have;
by year;
run;
proc sgplot data=have;
by year;
vbarparm category=Geo response=University / discreteoffset=-0.17 barwidth=0.3;
vbarparm category=Geo response=College / discreteoffset=0.17 barwidth=0.3;
yaxis valuesdisplay=(0 to 100 by 10) label="Percentage (%) " labelattrs=(size=13 );
xaxis label="Department" labelattrs=(size=13) fitpolicy=rotatethin valuesrotate=vertical;
run;
You need to sort the dataset by proc sort and use the by statement in proc sgplot as below
proc sort data=have;
by year;
run;
proc sgplot data=have;
by year;
vbarparm category=Geo response=University / discreteoffset=-0.17 barwidth=0.3;
vbarparm category=Geo response=College / discreteoffset=0.17 barwidth=0.3;
yaxis valuesdisplay=(0 to 100 by 10) label="Percentage (%) " labelattrs=(size=13 );
xaxis label="Department" labelattrs=(size=13) fitpolicy=rotatethin valuesrotate=vertical;
run;
Hi Jag....Thanks for your response. It works but not too sure why the "BY" is highlighted in red in the code....I was expecting it to be in blue. How do you suppress the Year from the by statement from appearing in the graph as I am using #byval(Year) in a Title statement. Thanks.
Hi Jag....that worked perfectly.....one more thing...can the second y axis be used as a line on the graph which will show to the overall percentage. I am trying to compare the departments with bars and would like to have a line to show the overall percentage if that is possible. Thanks.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.