BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xiangpang
Quartz | Level 8

hi,

Anyone know how to set range for scatter plot in proc template? 

 

I want to make two scatter plot side by side in proc template, with same x range and y range. how to do it?

 

Thanks

 

proc template;   
define statgraph scatter;      
layout gridded / columns=2 row=1;             
layout overlay;             
        scatterplot x=height1 y=weight1;            
endlayout;        
layout overlay;             
       scatterplot x=height2 y=weight2;             
endlayout  ;      
endlayout;   
end; 
run;
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

You'll want to use a LAYOUT LATTICE instead of a LAYOUT GRIDDED, and you will want to set the COLUMNDATARANGE and ROWDATARANGE to UNIONALL so that the data ranges from all cells are included in the axis range. Here is a simple example:

 

proc template;
define statgraph scatter;
begingraph;
layout lattice / columns=2 rows=1 columndatarange=unionall rowdatarange=unionall;
layout overlay;
        scatterplot x=height1 y=weight1;
endlayout;
layout overlay;
       scatterplot x=height2 y=weight2;
endlayout  ;
endlayout;
endgraph;
end;
run;

data class;
set sashelp.class;
height1 =height;
weight1=weight;
height2=height*2;
weight2=weight*2;
run;

proc sgrender data=class template=scatter; run;

 

Hope this helps!

Dan

View solution in original post

4 REPLIES 4
Reeza
Super User

Set xaxisopts and yaxisopts. 

 

See example below which is for a survival curve. 

https://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_templt_a000...

 

layout overlay / xaxisopts=(shortlabel=XNAME offsetmin=.05
   linearopts=(viewmax=MAXTIME tickvaluelist=XTICKVALS
   tickvaluefitpolicy=XTICKVALFITPOL)) yaxisopts=(label=
   "Survival Probability" shortlabel="Survival" linearopts=(viewmin=
   0 viewmax=1 tickvaluelist=(0 .2 .4 .6 .8 1.0)));

 

xiangpang
Quartz | Level 8

thanks for your help

DanH_sas
SAS Super FREQ

You'll want to use a LAYOUT LATTICE instead of a LAYOUT GRIDDED, and you will want to set the COLUMNDATARANGE and ROWDATARANGE to UNIONALL so that the data ranges from all cells are included in the axis range. Here is a simple example:

 

proc template;
define statgraph scatter;
begingraph;
layout lattice / columns=2 rows=1 columndatarange=unionall rowdatarange=unionall;
layout overlay;
        scatterplot x=height1 y=weight1;
endlayout;
layout overlay;
       scatterplot x=height2 y=weight2;
endlayout  ;
endlayout;
endgraph;
end;
run;

data class;
set sashelp.class;
height1 =height;
weight1=weight;
height2=height*2;
weight2=weight*2;
run;

proc sgrender data=class template=scatter; run;

 

Hope this helps!

Dan

xiangpang
Quartz | Level 8

Thanks, that helps

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 1573 views
  • 3 likes
  • 3 in conversation