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

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!!!!!

1 ACCEPTED SOLUTION
3 REPLIES 3
ballardw
Super User

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.

AncaTilea
Pyrite | Level 9

Thank you, Rick! I've been trying to indent the forest plot for months!

🙂

Now it's indented!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 2130 views
  • 4 likes
  • 3 in conversation