I am trying to create a sem-log graph using proc template. I am able to create linear graph, but How we can create it, I am new to how to derive geometric means, std and how they used in semi -log graph and how to adjust the y axis values. I also have another request ,how We can adjust the legend highlighted in the image. I am looking to have legends one top of the other instead of horizontal. I really appreciate your help. Thanks
Present legend alignment
---o--- F ---*--- M
Req legend alignment
---o--- F
---*--- M
Linear Graph Image
proc means data = sashelp.class nway;
class age sex;
var weight;
output out= class_mean n=n mean= _MEAN std= sd ;
run;
data mean1;
set class_mean;
lower = _MEAN - sd;
upper = _MEAN - sd;
run;
ods path(prepend) work.templat(update);
proc template;
define statgraph series;
begingraph/ BORDER=False datasymbols=( circle Asterisk) ;
layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;
layout overlay / xaxisopts=( label=('Age') tickvalueattrs=(family='Courier New' size=8 ) labelattrs=(family='Courier New' size=8 )
linearopts=( viewmin=10 viewmax=20 tickvaluesequence=( start=0.0 end=20 increment=1)))
yaxisopts=( label=('weight)') labelattrs=(family='Courier New' size=8 ) tickvalueattrs=(family='Courier New' size=8 )
linearopts=( viewmin=40 viewmax=160.0 tickvaluesequence=( start=0.0 end=160.0 increment=20.0)));
seriesplot x=age y= _MEAN / group=sex name='series' display=(markers) connectorder=xaxis ;
scatterplot x=age y= _MEAN / yerrorupper = upper yerrorlower = lower group=trtan name='scatter';
discretelegend 'series' / opaque=false border=true halign=right valign=top displayclipped=true across=2 order=rowmajor location=inside titleattrs=(family='Courier New' size=8 );
endlayout;
endlayout;
endgraph;
end;
run;
ods graphics on/ width=9 in height=4.6 in ;
options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline
noquotelenmax ;
ods escapechar = '^';
ods results on;
ods listing close;
ods rtf file = "&location..\chk.rtf"
style = _table nogtitle nogfootnote;
proc sgrender data=mean1 template=series;
run;
ods rtf close;
ods listing close;
I am not sure if it is what you want .
proc template;
define statgraph series;
begingraph/ BORDER=False datasymbols=( circle Asterisk) ;
layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;
layout overlay / xaxisopts=( label=('Age') tickvalueattrs=(family='Courier New' size=8 ) labelattrs=(family='Courier New' size=8 )
linearopts=( viewmin=10 viewmax=20 tickvaluesequence=( start=0.0 end=20 increment=1)))
yaxisopts=( label=('weight)') labelattrs=(family='Courier New' size=8 ) tickvalueattrs=(family='Courier New' size=8 )
type=log
linearopts=( viewmin=40 viewmax=160.0 tickvaluesequence=( start=0.0 end=160.0 increment=20.0)));
seriesplot x=age y= _MEAN / group=sex name='series' display=(markers) connectorder=xaxis ;
scatterplot x=age y= _MEAN / yerrorupper = upper yerrorlower = lower group=trtan name='scatter';
discretelegend 'series' / opaque=false border=true halign=right valign=top displayclipped=true
across=1 /*<------*/
order=rowmajor location=inside titleattrs=(family='Courier New' size=8 );
endlayout;
endlayout;
endgraph;
end;
run;
If you want "geometric means" , check
proc univariate data=have outtable=want noprint;
var have;
run;
Check geometric means in table WANT .
Hi, sorry for the confusion. I am looking to generate semi-log graph, I used type= log in the yaxisopts . how ever it still generating the linear graph. How to generate semi -log graph for the same data?
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 25. Read more here about why you should contribute and what is in it for you!
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.