Hello SAS Experts, Masters and Gurus!
I am trying to create a forestplot-like graph, using PROC TEMPLATE.
Most things work as I expect to work.
However, I have 2 questions:
(1) I would like to ident the "subgroup" labels on the y-axis, like this:
Gender
Male
Female
...
(2) I would like the lines (mean +/- s.e.) to alternate between solid and dashed (so, gender has lines black and solid, race has lines gray and dashed...)
My code is below and the sample data is attached:
/*hoping to get the leading-blanks to stay in the format*/
data _null_;
call symput('blk','A0'X);
run;
proc format;
value $ lab
'Male' = "&blk.&blk. Male"
'Female' = "&blk.&blk. Female"
'Black' = "&blk.&blk. Black"
'White' = "&blk.&blk. Non-Black"
' 43 years' = "&blk.&blk. 43 years"
' 66 years' = "&blk.&blk. 66 years"
' 82 years' = "&blk.&blk. 82 years"
;
quit;
proc template;
define statgraph sgdesign;
dynamic _ESTIMATE _LABEL _GRP_VAR _ESTIMATE2 _UPPER _LOWER;
begingraph / designwidth=1408 designheight=807;
DiscreteAttrMap name="__ATTRMAP__";
Value "1" / markerattrs=( color=black symbol=circle)
lineattrs=( color=black pattern=2);
Value "2" / markerattrs=( color=grayaa symbol=plus)
lineattrs=( color=grayaa pattern=3);
Value "3" / markerattrs=( color=black symbol=circle)
lineattrs=( color=black pattern=2);
EndDiscreteAttrMap;
DiscreteAttrVar attrvar=my_grp var=_grp_var attrmap="__ATTRMAP__";
layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;
layout overlay / xaxisopts=( display=(TICKS TICKVALUES LINE LABEL )
griddisplay=off
label=('Mean (95% Confidence Interval) of eGFR Slope')
labelattrs=(size=14 style=NORMAL weight=BOLD )
tickvalueattrs=(size=14 ))
yaxisopts=( reverse=true display=(TICKS TICKVALUES LINE )
griddisplay=off
labelattrs=GraphTitleText(size=14 )
tickvalueattrs=(size=14 )
gridattrs=(color=CX848284 pattern=2 thickness=1 ));
scatterplot x=_ESTIMATE y=_LABEL /
group=my_grp
datalabel=_ESTIMATE2 datalabelposition=TOP DATALABELATTRS = (size = 14)
xerrorupper=_UPPER xerrorlower=_LOWER
name='scatter'
markerattrs=(symbol=CIRCLEFILLED size=15 weight=bold )
errorbarattrs=(thickness=2 );
referenceline x = 0 / lineattrs = (thickness=3 pattern=2 color=CX848284);
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data = have template = sgdesign;
dynamic _ESTIMATE = "ESTIMATE" _LABEL = "LABEL" _GRP_VAR = "'GRP_VAR'n"
_ESTIMATE2 = "ESTIMATE" _UPPER = "UPPER" _LOWER = "LOWER";
run;
Thank you!!!!!
Have you seen this blog post? Forest Plot with Subgroups - Graphically Speaking
Have you seen this blog post? Forest Plot with Subgroups - Graphically Speaking
A quick and dirty way that often works when you want leading blanks displayed but SAS insists on removing them is to use a NULL character instead of a space. This is the ASCII 255, I'll let you figure the hex, or can be entered in the editor by holding down the ALT key and typing 255 (on WINDOWS systems at least). If you use this approach I recommend documenting it as it isn't obvious what is going on.
Thank you, Rick! I've been trying to indent the forest plot for months!
🙂
Now it's indented!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.