BookmarkSubscribeRSS Feed
Relax
Fluorite | Level 6

Hi all,

 

I used the posted code to create a scatter plot template.  I want to use displaysecondary option to change the second y-axis tick values interval like from 0 to 200, but it doesn't work.  Is there anything wrong with my code?

 

Thanks!

proc template;
define statgraph scatter3;
begingraph / backgroundcolor=CXD1D0CE border=true borderattrs=(color=CXEDDA74 thickness=5);
entrytitle halign=left textattrs=(size=15pt) "Plot";
entrytitle halign=left textattrs=(size=12pt weight=normal) "Scatter Plot" / opaque=true backgroundcolor=CXFFFFFF;
layout datalattice rowvar=x1 / 
		   headerlabeldisplay=value rowheaders=left
                   rowaxisopts=(griddisplay=on gridattrs=(pattern=dash) display=(ticks tickvalues)
		   linearopts=(viewmin=400 viewmax=1400) displaysecondary=(tickvalues=(0 to 200 by 50))) 
		   columnaxisopts=(griddisplay=on gridattrs=(pattern=dash) labelattrs=(size=12pt weight=normal))
		   headerbackgroundcolor=CXFFFFFF headerlabelattrs=(size=10pt weight=normal);
layout prototype;  

 

4 REPLIES 4
ballardw
Super User

Are you looking for ROW2AXISOPTS=(axis-options)?

 

It isn't clear exactly what you are attempting since no actual plot statements are shown or data accompanies the code.

 

Can you show your entire code using a SAS supplied data set such as SASHELP.CARS or similar if you don't want to share data.

Relax
Fluorite | Level 6

Thank you for your reply!

 

Here attached is my entire code using SAS supplied data set SASHELP.CARS, and the image is the result to run the code.  What I attempt to do is to change the interval of the second y-axis, like the axis of Horsepower shown in the scatter plot.  The range for Horsepower is from 100 to 500, but I want it to be from 0 to 400.  I have tried to use displaysecondary option, but it doesn't work.  How could I do that?

 

Thanks.

proc sql;
create table CARS as
select * 
from sashelp.cars
where Type = "SUV" or Type = "Sedan";
quit;

proc template;
define statgraph scatter;
begingraph / backgroundcolor=CXD1D0CE border=true borderattrs=(color=CXEDDA74 thickness=5);
entrytitle halign=left textattrs=(size=15pt) "Plot";
entrytitle halign=left textattrs=(size=12pt weight=normal) "Scatter Plot" / opaque=true backgroundcolor=CXFFFFFF;
layout datalattice rowvar=Type / 
				   headerlabeldisplay=value rowheaders=left
                   rowaxisopts=(griddisplay=on gridattrs=(pattern=dash) display=(ticks tickvalues))
				   columnaxisopts=(griddisplay=on gridattrs=(pattern=dash) labelattrs=(size=12pt weight=normal))
				   headerbackgroundcolor=CXFFFFFF headerlabelattrs=(size=10pt weight=normal);
layout prototype;
scatterplot x=MPG_City y=Cylinders / markerattrs=(color=CXC11B17 symbol=circlefilled) name='a';
scatterplot x=MPG_City y=EngineSize / markerattrs=(color=CX57E964 symbol=circlefilled)  name='b';
scatterplot x=MPG_City y=Horsepower / yaxis=y2 markerattrs=(color=CX2B65EC symbol=circlefilled)  name='c';
endlayout;
sidebar / align=bottom;
	discretelegend "a" "b" "c"/ border=false valueattrs=(size=11pt);
endsidebar;
endlayout;
endgraph;
end;
run;

proc sgrender data=CARS template=scatter;
run;

Capture.PNG 

ballardw
Super User

See if this can be modified to your need

proc template;
define statgraph scatter;
begingraph / backgroundcolor=CXD1D0CE border=true borderattrs=(color=CXEDDA74 thickness=5);
   entrytitle halign=left textattrs=(size=15pt) "Plot";
   entrytitle halign=left textattrs=(size=12pt weight=normal) "Scatter Plot" / opaque=true backgroundcolor=CXFFFFFF;
   layout datalattice rowvar=Type / 
   				   headerlabeldisplay=value rowheaders=left
                  rowaxisopts=(griddisplay=on gridattrs=(pattern=dash) display=(ticks tickvalues))
   				   columnaxisopts=(griddisplay=on gridattrs=(pattern=dash) labelattrs=(size=12pt weight=normal))
   				   headerbackgroundcolor=CXFFFFFF headerlabelattrs=(size=10pt weight=normal)
                  row2axisopts=(linearopts= (viewmin=0 viewmax=500 tickvaluelist=(0 250 500) ) )
   ;
   layout prototype;
      scatterplot x=MPG_City y=Cylinders / markerattrs=(color=CXC11B17 symbol=circlefilled) name='a';
      scatterplot x=MPG_City y=EngineSize / markerattrs=(color=CX57E964 symbol=circlefilled)  name='b';
      scatterplot x=MPG_City y=Horsepower / yaxis=y2 markerattrs=(color=CX2B65EC symbol=circlefilled)  name='c';
      
   endlayout;
   sidebar / align=bottom;
   	discretelegend "a" "b" "c"/ border=false valueattrs=(size=11pt);
   endsidebar;
   endlayout;
endgraph;
end;
run;

proc sgrender data=CARS template=scatter;
run;

The ROW2AXISOPTS sets the axis appearance options for the second axis, you need the LINEAROPTS=() to set linear axis specific options. The VIEWMIN and VIEWMAX set the range of values and if not present the displayed Y values get truncated (at least on my system)

 

Relax
Fluorite | Level 6

It works now.  Thank you very much.  I appreciate your help!

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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
  • 4 replies
  • 1167 views
  • 0 likes
  • 2 in conversation