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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2287 views
  • 3 likes
  • 3 in conversation