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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.