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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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