proc sgplot data=final; /*discreteoffset to seperate the two box plot*/ /* the same offsets must be used in both YAXIS and Y2AXIS stmts */ scatter x=AVISITN y=mean / discreteoffset=0.5 YErrorUpper=uclm YErrorLower=lclm ; series x=AVISITN y=mean / ; scatter x=AVISITN y=mean1 /Y2Axis discreteoffset=-0.5 YErrorUpper=uclm1 YErrorLower=lclm1; series x=AVISITN y=mean1/ Y2Axis; /*reference line*/ refline 0 / axis=y; /*grid : line */ yaxis label="A (unit1)" offsetmax=0.1 offsetmax=0.1 values=(-2 to 0 by 0.2); y2axis label="A (unit2)" offsetmax=0.1 offsetmax=0.1 values=(-1.0 to 0 by 0.1); run;
use different axis for different units:
The key here is that the X axis variable you have is not discrete. Therefore, the DISCRETEOFFSET option is ignored. In this case, you need to explicitly tell the XAXIS to be discrete. Add the following line and your code should work as expected:
Hope this helps!
Dan, I appreciate your help, my figure looks good now.
Another question, Can y2axis be used in proc template?
I'm not sure I'm understanding what your looking for, but I just posted a question using offsetmin and offsetmax that shows how to completely separate the y2axis. So the bottom of half of the plot shows data plotted against yaxis, and the top half shows data plotted against y2axis:
(My question there is whether SGPLOT can do this with 3 y axes...)
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.
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.