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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 1 reply
  • 333 views
  • 0 likes
  • 2 in conversation