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;
Thank you. You across option worked for me. However type= log is not creating the semi-log graph. it creating linear graph only can you please suggest where I am doing wrong. I don't see any error in log either.
Log
***********************************************************
63208
63209 proc means data = sashelp.class nway;
63210 class age sex;
63211 var weight;
63212 output out= class_mean n=n mean= _MEAN std= sd ;
63213 run;
WARNING: No output destinations active.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS_MEAN has 11 observations and 7 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
63214
63215 data mean1;
63216 set class_mean;
63217
63218 lower = _MEAN - sd;
63219 upper = _MEAN - sd;
63220 run;
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
4 at 63218:15 4 at 63219:15
NOTE: There were 11 observations read from the data set WORK.CLASS_MEAN.
NOTE: The data set WORK.MEAN1 has 11 observations and 9 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
63221
63222 ods path(prepend) work.templat(update);
63223 proc template;
63224 define statgraph series;
63225 begingraph/ BORDER=False datasymbols=( circle Asterisk) ;
63226 layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;
63227 layout overlay / xaxisopts=( label=('Age') tickvalueattrs=(family='Courier New' size=8 ) labelattrs=(family='Courier New' size=8 )
63228 linearopts=( viewmin=10 viewmax=20 tickvaluesequence=( start=0.0 end=20 increment=1)))
63229 yaxisopts=( label=('weight)') type=log labelattrs=(family='Courier New' size=8 ) tickvalueattrs=(family='Courier New' size=8 )
63230 linearopts=( viewmin=40 viewmax=160.0 tickvaluesequence=( start=0.0 end=160.0 increment=20.0)));
63231 seriesplot x=age y= _MEAN / group=sex name='series' display=(markers) connectorder=xaxis ;
63232 scatterplot x=age y= _MEAN / yerrorupper = upper yerrorlower = lower group=trtan name='scatter';
63233 discretelegend 'series' / opaque=false border=true halign=right valign=top displayclipped=true across=2 order=rowmajor location=inside
63233 ! titleattrs=(family='Courier New' size=8 );
63234 endlayout;
63235 endlayout;
63236 endgraph;
63237 end;
NOTE: Overwriting existing template/link: Series
NOTE: STATGRAPH 'Series' has been saved to: WORK.TEMPLAT
63238 run;
NOTE: PROCEDURE TEMPLATE used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
63239
63240
63241 ods graphics on/ width=9 in height=4.6 in ;
63242
63243 options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline
63244 noquotelenmax ;
63245 ods escapechar = '^';
63246 ods results on;
63247 ods listing close;
63248 ods rtf file = "&location\chk.rtf"
63249 style = rtf nogtitle nogfootnote;
NOTE: Writing RTF Body file:&location\chk.rtf
63250
63251 proc sgrender data=mean1 template=series;
63252
63253 run;
NOTE: There were 11 observations read from the data set WORK.MEAN1.
NOTE: PROCEDURE SGRENDER used (Total process time):
real time 0.19 seconds
cpu time 0.12 seconds
63254 ods rtf close;
63255 ods listing close;
******************************************
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)') type=log 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 = rtf nogtitle nogfootnote;
proc sgrender data=mean1 template=series;
run;
ods rtf close;
ods listing close;
The code really worked for me:
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)') type=log 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;
proc sgrender data=mean1 template=series;
run;
ods listing close;
Try the following y-axis options:
yaxisopts=( type=log tickvalueattrs=(family='Courier New' size=8 )
logopts=(base=10 tickvaluepriority=true tickintervalstyle=logexpand tickvaluelist=( 0.1 1 10 100 1000) minorticks=true)
label='weight' labelattrs=(family='Courier New' size=8 ) );
Below is the output:
SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.
Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!
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.