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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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