BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellohere
Pyrite | Level 9

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

1 REPLY 1
ballardw
Super User

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-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 525 views
  • 0 likes
  • 2 in conversation