I have code below, trying to show up refence line for y2axis. But it does not work. Any one know how?!
data test;
do i=1 to 1000;
x=i;
y1=sin(i*3.14159/100)*10+100;
y2=cos(i*3.14159/100);
output;
end;
run;quit;
%let xvar=x;
proc sgplot data=test;
series x=&xvar. y=y1/ lineattrs=(color=blue thickness=2.0 pattern=solid);
series x=&xvar. y=y2/y2axis lineattrs=(color=pink thickness=1.2 pattern=solid);
refline 100 /axis=y2axis lineattrs=(color=red thickness=2.0) ;
run;quit;
Syntax was almost right: You don't use axis=y2axis like in the series because you have the option is axis= not a bare name, so only need axis=y2.
proc sgplot data=test; series x=&xvar. y=y1/ lineattrs=(color=blue thickness=2.0 pattern=solid); series x=&xvar. y=y2/y2axis lineattrs=(color=pink thickness=1.2 pattern=solid); refline 100 /axis=y2 lineattrs=(color=red thickness=2.0) ; run;quit;
However the range of the values you show for the example data only has a range of 0 to 1 on the Y2 axis (right side of the graph) so doesn't appear on the graph.
Syntax was almost right: You don't use axis=y2axis like in the series because you have the option is axis= not a bare name, so only need axis=y2.
proc sgplot data=test; series x=&xvar. y=y1/ lineattrs=(color=blue thickness=2.0 pattern=solid); series x=&xvar. y=y2/y2axis lineattrs=(color=pink thickness=1.2 pattern=solid); refline 100 /axis=y2 lineattrs=(color=red thickness=2.0) ; run;quit;
However the range of the values you show for the example data only has a range of 0 to 1 on the Y2 axis (right side of the graph) so doesn't appear on the graph.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.