BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
twildone
Pyrite | Level 9

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
twildone
Pyrite | Level 9

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.

Jagadishkatam
Amethyst | Level 16
Using the NOBYLINE system option will cause the BY-line to not be printed.

try using below option and run the graph.

options nobyline;
Thanks,
Jag
twildone
Pyrite | Level 9

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 969 views
  • 2 likes
  • 2 in conversation