<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem Forest Plot X - axis control with negative LCL Values using SAS %forestmacro in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837296#M23193</link>
    <description>&lt;P&gt;&amp;nbsp;I came across the %forestmacro from the SAS. I am running into two issues.&lt;/P&gt;
&lt;P&gt;1. How I can control the x- axis values based on my requirements like min. max and offsets?&lt;/P&gt;
&lt;P&gt;2. When I have the the negative values by default it changing the whole x- axis labels&amp;nbsp; and causing the compress of bars.&lt;/P&gt;
&lt;P&gt;Please guide me in the macro where I can adjust them according to my requirement and have the flexibility. Thank you for your time.&lt;/P&gt;
&lt;P&gt;I am attaching my output and warning in log .&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1665094750758.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76003iA23DF6B0255C9268/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1665094750758.png" alt="SASuserlot_0-1665094750758.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_1-1665094803557.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76004i412303724E66E0E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_1-1665094803557.png" alt="SASuserlot_1-1665094803557.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ForestMacro (
       Data=,    	    /*--Data Set Name (Required)--*/
       Study=,          /*--Variable name for Study (Required)--*/ 
       OddsRatio=,      /*--Variable name for Odds Ratio (Required)--*/ 
       LCL=,            /*--Variable name for Lower Confidence Limit (Required)--*/ 
       UCL=,            /*--Variable name for Upper Confidence Limit (Required)--*/ 
       Group=,          /*--Variable name for Study Type--*/ 
       Weight=,         /*--Variable name for Study Weight in %--*/
	   StatCol1=,       /*--Variable name for Stat Column 1--*/
	   StatCol2=,       /*--Variable name for Stat Column 2--*/
	   StatCol3=,       /*--Variable name for Stat Column 3--*/
	   StatCol4=,       /*--Variable name for Stat Column 4--*/
	   DisplayCols=YES, /*--Display the columns for OR, LCL, UCL &amp;amp; Weight--*/
	   WtFactor=,       /*--Multiplier factor for Study Weights--*/
                        /*--If not provided WtFactor is computed internally--*/
	   Bands=YES,       /*--Draw Horizontal Alternating Bands--*/
	   Borders=NO,      /*--Draw Borders--*/
	   GraphWalls=NO,   /*--Draw Filled Walls behind the Graph--*/
	   StatWalls=NO,    /*--Draw Filled Walls behind the Statistics Tables--*/
	   Width=6.4in,     /*--Default width of the graph in pixels--*/
	   Height=,         /*--Default height of the graph is computed based on number of observations--*/
	   LabelColWidth=0.2,                /*--Fractional width for Label Column--*/
	   Label1=Favors Treatment,          /*--Favorable Label--*/
	   Label2=Favors Control,            /*--Unfavorable Label--*/
	   PlotTitle=Odds Ratio and 95% CL,  /*--Plot Title--*/
	   FootNote=,                        /*--Graph Footnote--*/
	   Title2=,                          /*--Graph title2--*/
	   Title=Impact of Treatment on Mortality by Study  /*--Graph Title--*/ 
);

%local  WeightVar MarkerSize GraphColWidth StatColWidth Border DisplaySecondary GraphWallDisplay StatWallDisplay;
%local  OddsLabel LowerLabel UpperLabel WeightLabel SLabel1 SLabel2 SLabel3 SLabel4;
%local  GraphHeight Ratio RowHeight HeaderHeight Nobs;

/*--Data, Study, OddsRatio, LCL and UCL are required   --*/
/*--Group is optional                                  --*/
/*--Terminatethese required parameters are not supplied--*/
%if %length(&amp;amp;Data) eq 0 %then %do;
%put The parameter 'Data' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;Study) eq 0 %then %do;
%put The parameter 'Study' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;LCL) eq 0 %then %do;
%put The parameter 'LCL' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;UCL) eq 0 %then %do;
%put The parameter 'UCL' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;OddsRatio) eq 0 %then %do;
%put The parameter 'OddsRatio' is required - Forest Macro Terminated.;
%goto finished;
%end;

/*--Initialize GraphHeight, Height per row and Height for other graph items--*/
%let GraphHeight=&amp;amp;Height;
%let RowHeight=22;
%let HeaderHeight=100;
%if %length(&amp;amp;Footnote) ne 0 %then %do;
  %let HeaderHeight=115;
%end;

/*--If the Weight column is not provided, use equal weights, and suppress display of Weight stat--*/
%if &amp;amp;Weight eq %then %do;
  %let WeightVar = _Weight;
  %let MarkerSize = 7;
%end; 
%else %do;
  %let WeightVar=&amp;amp;Weight;
  %let MarkerSize = 0;
%end;

/*--Set up GTL options for borders--*/
%let DisplaySecondary = displaysecondary=none;
%let Borders=%upcase(&amp;amp;Borders);
%if &amp;amp;Borders eq YES or &amp;amp;Borders eq Y %then %do;
  %let Border = line;
  %let DisplaySecondary = displaysecondary=(line);
%end;

/*--Set up GTL options for GraphWall Display--*/
%let GraphWallDisplay = walldisplay=none;
%let GraphWalls=%upcase(&amp;amp;GraphWalls);
%if &amp;amp;GraphWalls eq YES or &amp;amp;GraphWalls eq Y %then %do;
  %let GraphWallDisplay = walldisplay=(fill);
%end; 

/*--Set up GTL options for StatWall Display--*/
%let StatWallDisplay = walldisplay=none;
%let StatWalls=%upcase(&amp;amp;StatWalls);
%if &amp;amp;StatWalls eq YES or &amp;amp;StatWalls eq Y %then %do;
  %let StatWallDisplay = walldisplay=(fill);
%end;

/*--Create Label Columns for standard and additional columns--*/

/*--Load Stat Column Label or name into macro for label column value--*/
%let dsid=%sysfunc(open(&amp;amp;Data));
%if &amp;amp;dsid %then %do;
    
    %let Nobs=%sysfunc(attrn(&amp;amp;dsid, nlobs));
	%if &amp;amp;Nobs eq 0 %then %do;
      %put The Data Set &amp;amp;Data has no observations - Forest Macro Terminated.;
      %let rc=%sysfunc(close(&amp;amp;dsid)); 
      %goto finished;
    %end;

    %if &amp;amp;Nobs gt 100 %then %do;
      %put The Data Set &amp;amp;Data has over 100 observations - Forest Macro Terminated.;
      %let rc=%sysfunc(close(&amp;amp;dsid)); 
      %goto finished;
    %end;

    /*--Count the number of stat columns--*/
    %let idx=0;
	
	/*--Column display information for the OddsRatio column--*/
	%let DisplayCols=%upcase(&amp;amp;DisplayCols);

    %if &amp;amp;DisplayCols eq YES or &amp;amp;DisplayCols eq Y %then %do;
      %let OddsLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;OddsRatio))));
  	  %if %length(&amp;amp;OddsLabel) eq 0 %then %let OddsLabel=&amp;amp;OddsRatio;
	  %let idx= %eval(&amp;amp;idx+1);

      %let LowerLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;LCL))));
  	  %if %length(&amp;amp;LowerLabel) eq 0 %then %let LowerLabel=&amp;amp;LCL;
	  %let idx= %eval(&amp;amp;idx+1);

      %let UpperLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;UCL))));
  	  %if %length(&amp;amp;UpperLabel) eq 0 %then %let UpperLabel=&amp;amp;UCL;
	  %let idx= %eval(&amp;amp;idx+1);

      %if &amp;amp;Weight ne %then %do;
        %let WeightLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;Weight))));
  	    %if %length(&amp;amp;WeightLabel) eq 0 %then %let WeightLabel=&amp;amp;Weight;
	    %let idx= %eval(&amp;amp;idx+1);
	  %end;
    %end;

	/*--Additional columns to be displayed--*/
    %if %length(&amp;amp;StatCol1) ne 0 %then %do;
      %let SLabel1=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol1))));
  	  %if %length(&amp;amp;SLabel1) eq 0 %then %let SLabel1=&amp;amp;StatCol1;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %if %length(&amp;amp;StatCol2) ne 0 %then %do;
      %let SLabel2=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol2))));
  	  %if %length(&amp;amp;SLabel2) eq 0 %then %let SLabel2=&amp;amp;StatCol2;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %if %length(&amp;amp;StatCol3) ne 0 %then %do;
      %let SLabel3=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol3))));
  	  %if %length(&amp;amp;SLabel3) eq 0 %then %let SLabel3=&amp;amp;StatCol3;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %if %length(&amp;amp;StatCol4) ne 0 %then %do;
      %let SLabel4=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol4))));
  	  %if %length(&amp;amp;SLabel4) eq 0 %then %let SLabel4=&amp;amp;StatCol4;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %let rc=%sysfunc(close(&amp;amp;dsid)); 

	/*--Set column weights based on number of stat columns--*/
    %let StatColWidth=%sysevalf(&amp;amp;idx * 0.075);
    %let GraphColWidth= %sysevalf(1.0 - &amp;amp;LabelColWidth - &amp;amp;StatColWidth);
%end;
%else %do;
    %put The data set &amp;amp;Data does not exist - Forest Macro Terminated.;
    %goto finished;
%end;

/*--Compute Weight Factor if not provided   --*/
/*--Estimate height of graph if not provided--*/
data _null_;
  set &amp;amp;Data end=last;
  retain totalweight 0;
  totalweight+wt;

  if last then do;
    %if &amp;amp;wtFactor eq %then %do;
      if totalweight &amp;lt;= 0 then totalweight=1;
      call symput ('wtFactor', 1 / totalweight);
    %end;
	/*--Estimate Ratio of Plot height by Graph Height--*/
	call symput ('Ratio', (_N_* &amp;amp;RowHeight)/(_N_* &amp;amp;RowHeight + &amp;amp;HeaderHeight));

    /*--Estimate the optimal height of the graph based on obs count--*/
    %if &amp;amp;Height eq %then %do;
	  call symput ('GraphHeight', _N_ * &amp;amp;RowHeight + &amp;amp;HeaderHeight);
	%end;
  end;
run;

/*--Append a PX only if this internally estimated--*/
%if &amp;amp;Height eq %then %do;
%let GraphHeight=&amp;amp;GraphHeight.px;
%end;

/*--Process Data--*/
data _forest;
  set &amp;amp;Data;
  format _wt PERCENT6.1;

  _ObsId=_N_;

  %if &amp;amp;Weight eq %then %do;
    &amp;amp;WeightVar=0;
  %end;

  label _wt=&amp;amp;WeightLabel;

  /*--If Group column is provided--*/
  %if %length(&amp;amp;Group) ne 0 %then %do;
    /*--Group=1 (Study) values will be drawn without a group role--*/
    if &amp;amp;group=1 then do;
	  _wt=&amp;amp;WeightVar / 100;
	  _grp=10;
      _or1 = &amp;amp;OddsRatio;
      _lcl1=&amp;amp;LCL; 
      _ucl1=&amp;amp;UCL;
      /*--Compute marker width--*/
      _x1=&amp;amp;OddsRatio / (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
      _x2=&amp;amp;OddsRatio * (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
    end;
  /*--Group=2 &amp;amp; 3 (SubGroup and Overall) values will be drawn with groupindex=2 &amp;amp; 3--*/
    else if &amp;amp;group &amp;gt; 1 then do;
      _grp=&amp;amp;group;
      _or2 = &amp;amp;OddsRatio;
    end;
  %end;
  %else %do;
    _wt=&amp;amp;WeightVar / 100;
    _grp=10;
    _or1 = &amp;amp;OddsRatio;
    _lcl1=&amp;amp;LCL; 
    _ucl1=&amp;amp;UCL;
    /*--Compute marker width--*/
    _x1=&amp;amp;OddsRatio / (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
    _x2=&amp;amp;OddsRatio * (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
  %end;

  /*--Create label columns for standard and additional statistic--*/
  %if %length(&amp;amp;OddsRatio) ne 0 %then %do;
    _OddsRatioLabel = symget('OddsLabel');
  %end;

  %if %length(&amp;amp;LCL) ne 0 %then %do;
    _LowerLabel = symget('LowerLabel');
  %end;

  %if %length(&amp;amp;UCL) ne 0 %then %do;
    _UpperLabel = symget('UpperLabel');
  %end;

  %if %length(&amp;amp;Weight) ne 0 %then %do;
    _WeightLabel = symget('WeightLabel');
  %end;

  %if %length(&amp;amp;StatCol1) ne 0 %then %do;
    _StatColLabel1 = symget('SLabel1');
	_StatCol1 = &amp;amp;StatCol1;
  %end;

  %if %length(&amp;amp;StatCol2) ne 0 %then %do;
    _StatColLabel2 = symget('SLabel2');
	_StatCol2 = &amp;amp;StatCol2;
  %end;

  %if %length(&amp;amp;StatCol3) ne 0 %then %do;
    _StatColLabel3 = symget('SLabel3');
	_StatCol3 = &amp;amp;StatCol3;
  %end;

  %if %length(&amp;amp;StatCol4) ne 0 %then %do;
    _StatColLabel4 = symget('SLabel4');
	_StatCol4 = &amp;amp;StatCol4;
  %end;
 
  run;

/*--Reverse the order to avoid putting axis reverse--*/
proc sort data=_forest out=_forest;
  by descending _ObsId;
  run;

/*--Add sequence numbers to each observation--*/
data _forest;
  set _forest;
  studyvalue=_n_;
run;

/*--Output values and formatted strings to data set--*/
data _forestFormat;
  set _forest end=last;
  keep label start end fmtname type hlo;
  retain fmtname '_Study' type 'n';
  label=&amp;amp;Study;
  start=studyvalue;
  end=studyvalue;
  output;
  if last then do;
    hlo='O';
	label='Other';
	output;
  end;
  run;

/*--Create Format from data set--*/
proc format library=work cntlin=_forestFormat;
  run;

/*--Apply format to study values--*/
/*--Compute width of box proportional to weight in log scale--*/
data _forest;
  format studyvalue _study.;
  set _forest;
  %let Bands=%upcase(&amp;amp;Bands);
  %if &amp;amp;Bands eq YES or &amp;amp;Bands eq Y %then %do;
    if mod(studyvalue, 2) = 0 then _StudyRef=StudyValue;
  %end;
  run;

/*--Compute top and bottom offsets--*/
data _null_;
  pct=&amp;amp;Ratio/nobs;
  thk=pct* 0.9 *100;
  call symputx("pct", pct);
  call symputx("pct2", 2*pct);
  call symputx("RefThickness", thk);
  call symputx("count", nobs);
  set _forest nobs=nobs;
run;

/*title;*/
/*options nodate nonumber;*/

/*--Define GTL template for graph--*/
proc template;
  define statgraph ForestMacro;
    begingraph / designwidth=&amp;amp;Width designheight=&amp;amp;GraphHeight;
	  entrytitle "&amp;amp;Title";
	  entryfootnote halign=left "&amp;amp;FootNote";
	  %if %length(&amp;amp;title2) ne 0 %then %do;
	    entrytitle "&amp;amp;title2" / textattrs=graphLabelText;
      %end;
	  layout lattice / columns=3 columnweights=(&amp;amp;LabelColWidth &amp;amp;GraphColWidth &amp;amp;StatColWidth) columngutter=0
                       rowdatarange=union;
        /*--Column # 1 contains the Study Labels using Secondary Y axis--*/
        layout overlay / walldisplay=none x2axisopts=(display=none)
                         yaxisopts=(linearopts=(tickvaluesequence=(start=1 end=&amp;amp;count increment=1))
                                    offsetmin=&amp;amp;pct2 offsetmax=&amp;amp;pct display=none
                                    displaysecondary=(tickvalues &amp;amp;border));
		  scatterplot y=studyvalue x=_or1 / yaxis=Y xaxis=X2 markerattrs=(size=0) includemissinggroup=true;
		  scatterplot y=studyvalue x=_or1 / yaxis=Y xaxis=X2 markerattrs=(size=0) includemissinggroup=true;
		endlayout;
	    /*--Column # 2 contains the graph--*/
        layout overlay / &amp;amp;GraphWallDisplay border=false
                         xaxisopts=(offsetmin=0  type=log logopts=(minorticks=true)
                                    label="&amp;amp;PlotTitle" display=(ticks tickvalues line) 
                                    displaysecondary=(label &amp;amp;border)) 
                         yaxisopts=(linearopts=(tickvaluesequence=(start=1 end=&amp;amp;count increment=1))
                                    offsetmin=&amp;amp;pct2 offsetmax=&amp;amp;pct display=none);

		  /*--Draw alternating bands using referenceline--*/
          %if &amp;amp;Bands eq YES or &amp;amp;Bands eq Y %then %do;
            referenceline y=_StudyRef / lineattrs=(thickness=&amp;amp;RefThickness.PCT) datatransparency=0.9;
		  %end;

          /*--Draw Markers for SubGroup and Overall values--*/
		  %if %length(&amp;amp;Group) ne 0 %then %do;
            scatterplot y=studyvalue x=_or2 / markerattrs=(symbol=diamondfilled size=10) group=_grp 
                      includemissinggroup=true index=_grp;
		  %end;
          /*--Draw OddsRatio and Limits for Study Values--*/
          scatterplot y=studyvalue x=_or1 / xerrorupper=_ucl1 xerrorlower=_lcl1 
                  markerattrs=graphdata1(symbol=squarefilled size=&amp;amp;MarkerSize);

		  /*--Draw box representing the weight of the study--*/
          vectorplot y=studyvalue x=_x2 xorigin=_x1 yorigin=studyvalue / lineattrs=GraphData1(thickness=8) 
                 arrowheads=false;

          /*--Draw Reference lines and labels--*/
          referenceline x=1;
          referenceline x=0.01 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  referenceline x=0.1 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  referenceline x=10 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  referenceline x=100 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  entry halign=left  "&amp;amp;Label1" / valign=bottom;
		  entry halign=right "&amp;amp;Label2" / valign=bottom;
		endlayout;

	    /*--Column # 2 contains the statistics data--*/
        layout overlay / &amp;amp;StatWallDisplay border=false
                         x2axisopts=(display=(tickvalues &amp;amp;border) displaysecondary=(line))
                         yaxisopts=(linearopts=(tickvaluesequence=(start=1 end=&amp;amp;count increment=1))
                                    offsetmin=&amp;amp;pct2 offsetmax=&amp;amp;pct 
                                    display=none &amp;amp;DisplaySecondary.);
          /*--Draw alternating bands using referenceline--*/
          %if &amp;amp;Bands eq YES %then %do;
            referenceline y=_StudyRef / lineattrs=(thickness=&amp;amp;RefThickness.PCT) datatransparency=0.9;
		  %end;

          /*--Draw standard statistics columns--*/
          %if &amp;amp;DisplayCols eq YES or &amp;amp;DisplayCols eq Y %then %do;
            scatterplot y=studyvalue x=_OddsRatioLabel / markercharacter=&amp;amp;OddsRatio xaxis=x2;
			scatterplot y=studyvalue x=_LowerLabel / markercharacter=&amp;amp;LCL xaxis=x2;
			scatterplot y=studyvalue x=_UpperLabel / markercharacter=&amp;amp;UCL xaxis=x2;
			%if &amp;amp;Weight ne %then %do;
              scatterplot y=studyvalue x=_WeightLabel / markercharacter=_wt xaxis=x2;
			%end;
		  %end;

		  /*--Draw additional statistics columns--*/
          %if %length(&amp;amp;StatCol1) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel1 / markercharacter=&amp;amp;StatCol1 xaxis=x2;
		  %end;

		  %if %length(&amp;amp;StatCol2) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel2 / markercharacter=&amp;amp;StatCol2 xaxis=x2;
		  %end;

          %if %length(&amp;amp;StatCol3) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel3 / markercharacter=&amp;amp;StatCol3 xaxis=x2;
		  %end;

          %if %length(&amp;amp;StatCol4) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel4 / markercharacter=&amp;amp;StatCol4 xaxis=x2;
		  %end;

		endlayout;
	  endlayout;
	endgraph;
  end;
run;

proc sgrender data=_forest template=ForestMacro description='Forest Plot';
  run;

%finished:
%mend ForestMacro;
*++++++++++++++++++++++++++++++++++++++++++++++++++++
End of Macro
++++++++++++++++++++++++++++++++++++++++++++++++++++;

data class ;
	set sashelp.class ;
 if _n_ &amp;lt;=4 then do;
 *Creating lcl negative values  and affecting the x axis in macro;
	  HR=0.042;
	  lcl=HR-0.052;
	  ucl=HR+0.01;
	  name1 = name||"its long name";
	  pvalue=0.019;

  end;
  else if _n_ &amp;gt;=5 and _n_&amp;lt;=9 then do;
	  HR=0.083;
	  lcl=HR-0.02;
	  ucl=HR+0.1;
	  name1=name;
	  pvalue=0.089;

  end;

  else if _n_ &amp;gt;=10 and _n_&amp;lt;=15 then do;
	  HR=0.346;
	  lcl=HR-0.11;
	  ucl=HR+0.3;
	  name1=name;
	  pvalue=0.004;

  end;

  else   do;
	  HR=0.449;
	  lcl=HR-0.21;
	  ucl=HR+0.3;
	  name1=name;
	  pvalue=0.45;
  end;

  Groupid=1;
 keep  hr ucl name1 lcl pvalue groupid;
run;

%ForestMacro(data=class, Study=name1, Group=GroupId, OddsRatio=HR,
LCL=lcl, UCL=ucl,Bands=NO, GraphWalls=NO, StatWalls=NO, Borders=NO, StatCol1=pvalue);



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Reference Macro link:&amp;nbsp;&lt;A href="https://support.sas.com/kb/43/855.html" target="_blank" rel="noopener"&gt;https://support.sas.com/kb/43/855.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 22:23:44 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2022-10-06T22:23:44Z</dc:date>
    <item>
      <title>Problem Forest Plot X - axis control with negative LCL Values using SAS %forestmacro</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837296#M23193</link>
      <description>&lt;P&gt;&amp;nbsp;I came across the %forestmacro from the SAS. I am running into two issues.&lt;/P&gt;
&lt;P&gt;1. How I can control the x- axis values based on my requirements like min. max and offsets?&lt;/P&gt;
&lt;P&gt;2. When I have the the negative values by default it changing the whole x- axis labels&amp;nbsp; and causing the compress of bars.&lt;/P&gt;
&lt;P&gt;Please guide me in the macro where I can adjust them according to my requirement and have the flexibility. Thank you for your time.&lt;/P&gt;
&lt;P&gt;I am attaching my output and warning in log .&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1665094750758.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76003iA23DF6B0255C9268/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1665094750758.png" alt="SASuserlot_0-1665094750758.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_1-1665094803557.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76004i412303724E66E0E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_1-1665094803557.png" alt="SASuserlot_1-1665094803557.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ForestMacro (
       Data=,    	    /*--Data Set Name (Required)--*/
       Study=,          /*--Variable name for Study (Required)--*/ 
       OddsRatio=,      /*--Variable name for Odds Ratio (Required)--*/ 
       LCL=,            /*--Variable name for Lower Confidence Limit (Required)--*/ 
       UCL=,            /*--Variable name for Upper Confidence Limit (Required)--*/ 
       Group=,          /*--Variable name for Study Type--*/ 
       Weight=,         /*--Variable name for Study Weight in %--*/
	   StatCol1=,       /*--Variable name for Stat Column 1--*/
	   StatCol2=,       /*--Variable name for Stat Column 2--*/
	   StatCol3=,       /*--Variable name for Stat Column 3--*/
	   StatCol4=,       /*--Variable name for Stat Column 4--*/
	   DisplayCols=YES, /*--Display the columns for OR, LCL, UCL &amp;amp; Weight--*/
	   WtFactor=,       /*--Multiplier factor for Study Weights--*/
                        /*--If not provided WtFactor is computed internally--*/
	   Bands=YES,       /*--Draw Horizontal Alternating Bands--*/
	   Borders=NO,      /*--Draw Borders--*/
	   GraphWalls=NO,   /*--Draw Filled Walls behind the Graph--*/
	   StatWalls=NO,    /*--Draw Filled Walls behind the Statistics Tables--*/
	   Width=6.4in,     /*--Default width of the graph in pixels--*/
	   Height=,         /*--Default height of the graph is computed based on number of observations--*/
	   LabelColWidth=0.2,                /*--Fractional width for Label Column--*/
	   Label1=Favors Treatment,          /*--Favorable Label--*/
	   Label2=Favors Control,            /*--Unfavorable Label--*/
	   PlotTitle=Odds Ratio and 95% CL,  /*--Plot Title--*/
	   FootNote=,                        /*--Graph Footnote--*/
	   Title2=,                          /*--Graph title2--*/
	   Title=Impact of Treatment on Mortality by Study  /*--Graph Title--*/ 
);

%local  WeightVar MarkerSize GraphColWidth StatColWidth Border DisplaySecondary GraphWallDisplay StatWallDisplay;
%local  OddsLabel LowerLabel UpperLabel WeightLabel SLabel1 SLabel2 SLabel3 SLabel4;
%local  GraphHeight Ratio RowHeight HeaderHeight Nobs;

/*--Data, Study, OddsRatio, LCL and UCL are required   --*/
/*--Group is optional                                  --*/
/*--Terminatethese required parameters are not supplied--*/
%if %length(&amp;amp;Data) eq 0 %then %do;
%put The parameter 'Data' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;Study) eq 0 %then %do;
%put The parameter 'Study' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;LCL) eq 0 %then %do;
%put The parameter 'LCL' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;UCL) eq 0 %then %do;
%put The parameter 'UCL' is required - Forest Macro Terminated.;
%goto finished;
%end;
%else %if %length(&amp;amp;OddsRatio) eq 0 %then %do;
%put The parameter 'OddsRatio' is required - Forest Macro Terminated.;
%goto finished;
%end;

/*--Initialize GraphHeight, Height per row and Height for other graph items--*/
%let GraphHeight=&amp;amp;Height;
%let RowHeight=22;
%let HeaderHeight=100;
%if %length(&amp;amp;Footnote) ne 0 %then %do;
  %let HeaderHeight=115;
%end;

/*--If the Weight column is not provided, use equal weights, and suppress display of Weight stat--*/
%if &amp;amp;Weight eq %then %do;
  %let WeightVar = _Weight;
  %let MarkerSize = 7;
%end; 
%else %do;
  %let WeightVar=&amp;amp;Weight;
  %let MarkerSize = 0;
%end;

/*--Set up GTL options for borders--*/
%let DisplaySecondary = displaysecondary=none;
%let Borders=%upcase(&amp;amp;Borders);
%if &amp;amp;Borders eq YES or &amp;amp;Borders eq Y %then %do;
  %let Border = line;
  %let DisplaySecondary = displaysecondary=(line);
%end;

/*--Set up GTL options for GraphWall Display--*/
%let GraphWallDisplay = walldisplay=none;
%let GraphWalls=%upcase(&amp;amp;GraphWalls);
%if &amp;amp;GraphWalls eq YES or &amp;amp;GraphWalls eq Y %then %do;
  %let GraphWallDisplay = walldisplay=(fill);
%end; 

/*--Set up GTL options for StatWall Display--*/
%let StatWallDisplay = walldisplay=none;
%let StatWalls=%upcase(&amp;amp;StatWalls);
%if &amp;amp;StatWalls eq YES or &amp;amp;StatWalls eq Y %then %do;
  %let StatWallDisplay = walldisplay=(fill);
%end;

/*--Create Label Columns for standard and additional columns--*/

/*--Load Stat Column Label or name into macro for label column value--*/
%let dsid=%sysfunc(open(&amp;amp;Data));
%if &amp;amp;dsid %then %do;
    
    %let Nobs=%sysfunc(attrn(&amp;amp;dsid, nlobs));
	%if &amp;amp;Nobs eq 0 %then %do;
      %put The Data Set &amp;amp;Data has no observations - Forest Macro Terminated.;
      %let rc=%sysfunc(close(&amp;amp;dsid)); 
      %goto finished;
    %end;

    %if &amp;amp;Nobs gt 100 %then %do;
      %put The Data Set &amp;amp;Data has over 100 observations - Forest Macro Terminated.;
      %let rc=%sysfunc(close(&amp;amp;dsid)); 
      %goto finished;
    %end;

    /*--Count the number of stat columns--*/
    %let idx=0;
	
	/*--Column display information for the OddsRatio column--*/
	%let DisplayCols=%upcase(&amp;amp;DisplayCols);

    %if &amp;amp;DisplayCols eq YES or &amp;amp;DisplayCols eq Y %then %do;
      %let OddsLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;OddsRatio))));
  	  %if %length(&amp;amp;OddsLabel) eq 0 %then %let OddsLabel=&amp;amp;OddsRatio;
	  %let idx= %eval(&amp;amp;idx+1);

      %let LowerLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;LCL))));
  	  %if %length(&amp;amp;LowerLabel) eq 0 %then %let LowerLabel=&amp;amp;LCL;
	  %let idx= %eval(&amp;amp;idx+1);

      %let UpperLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;UCL))));
  	  %if %length(&amp;amp;UpperLabel) eq 0 %then %let UpperLabel=&amp;amp;UCL;
	  %let idx= %eval(&amp;amp;idx+1);

      %if &amp;amp;Weight ne %then %do;
        %let WeightLabel=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;Weight))));
  	    %if %length(&amp;amp;WeightLabel) eq 0 %then %let WeightLabel=&amp;amp;Weight;
	    %let idx= %eval(&amp;amp;idx+1);
	  %end;
    %end;

	/*--Additional columns to be displayed--*/
    %if %length(&amp;amp;StatCol1) ne 0 %then %do;
      %let SLabel1=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol1))));
  	  %if %length(&amp;amp;SLabel1) eq 0 %then %let SLabel1=&amp;amp;StatCol1;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %if %length(&amp;amp;StatCol2) ne 0 %then %do;
      %let SLabel2=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol2))));
  	  %if %length(&amp;amp;SLabel2) eq 0 %then %let SLabel2=&amp;amp;StatCol2;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %if %length(&amp;amp;StatCol3) ne 0 %then %do;
      %let SLabel3=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol3))));
  	  %if %length(&amp;amp;SLabel3) eq 0 %then %let SLabel3=&amp;amp;StatCol3;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %if %length(&amp;amp;StatCol4) ne 0 %then %do;
      %let SLabel4=%sysfunc(varlabel(&amp;amp;dsid, %sysfunc(varnum(&amp;amp;dsid,&amp;amp;StatCol4))));
  	  %if %length(&amp;amp;SLabel4) eq 0 %then %let SLabel4=&amp;amp;StatCol4;
	  %let idx= %eval(&amp;amp;idx+1);
    %end;

    %let rc=%sysfunc(close(&amp;amp;dsid)); 

	/*--Set column weights based on number of stat columns--*/
    %let StatColWidth=%sysevalf(&amp;amp;idx * 0.075);
    %let GraphColWidth= %sysevalf(1.0 - &amp;amp;LabelColWidth - &amp;amp;StatColWidth);
%end;
%else %do;
    %put The data set &amp;amp;Data does not exist - Forest Macro Terminated.;
    %goto finished;
%end;

/*--Compute Weight Factor if not provided   --*/
/*--Estimate height of graph if not provided--*/
data _null_;
  set &amp;amp;Data end=last;
  retain totalweight 0;
  totalweight+wt;

  if last then do;
    %if &amp;amp;wtFactor eq %then %do;
      if totalweight &amp;lt;= 0 then totalweight=1;
      call symput ('wtFactor', 1 / totalweight);
    %end;
	/*--Estimate Ratio of Plot height by Graph Height--*/
	call symput ('Ratio', (_N_* &amp;amp;RowHeight)/(_N_* &amp;amp;RowHeight + &amp;amp;HeaderHeight));

    /*--Estimate the optimal height of the graph based on obs count--*/
    %if &amp;amp;Height eq %then %do;
	  call symput ('GraphHeight', _N_ * &amp;amp;RowHeight + &amp;amp;HeaderHeight);
	%end;
  end;
run;

/*--Append a PX only if this internally estimated--*/
%if &amp;amp;Height eq %then %do;
%let GraphHeight=&amp;amp;GraphHeight.px;
%end;

/*--Process Data--*/
data _forest;
  set &amp;amp;Data;
  format _wt PERCENT6.1;

  _ObsId=_N_;

  %if &amp;amp;Weight eq %then %do;
    &amp;amp;WeightVar=0;
  %end;

  label _wt=&amp;amp;WeightLabel;

  /*--If Group column is provided--*/
  %if %length(&amp;amp;Group) ne 0 %then %do;
    /*--Group=1 (Study) values will be drawn without a group role--*/
    if &amp;amp;group=1 then do;
	  _wt=&amp;amp;WeightVar / 100;
	  _grp=10;
      _or1 = &amp;amp;OddsRatio;
      _lcl1=&amp;amp;LCL; 
      _ucl1=&amp;amp;UCL;
      /*--Compute marker width--*/
      _x1=&amp;amp;OddsRatio / (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
      _x2=&amp;amp;OddsRatio * (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
    end;
  /*--Group=2 &amp;amp; 3 (SubGroup and Overall) values will be drawn with groupindex=2 &amp;amp; 3--*/
    else if &amp;amp;group &amp;gt; 1 then do;
      _grp=&amp;amp;group;
      _or2 = &amp;amp;OddsRatio;
    end;
  %end;
  %else %do;
    _wt=&amp;amp;WeightVar / 100;
    _grp=10;
    _or1 = &amp;amp;OddsRatio;
    _lcl1=&amp;amp;LCL; 
    _ucl1=&amp;amp;UCL;
    /*--Compute marker width--*/
    _x1=&amp;amp;OddsRatio / (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
    _x2=&amp;amp;OddsRatio * (10 ** (&amp;amp;WeightVar*&amp;amp;WtFactor/2));
  %end;

  /*--Create label columns for standard and additional statistic--*/
  %if %length(&amp;amp;OddsRatio) ne 0 %then %do;
    _OddsRatioLabel = symget('OddsLabel');
  %end;

  %if %length(&amp;amp;LCL) ne 0 %then %do;
    _LowerLabel = symget('LowerLabel');
  %end;

  %if %length(&amp;amp;UCL) ne 0 %then %do;
    _UpperLabel = symget('UpperLabel');
  %end;

  %if %length(&amp;amp;Weight) ne 0 %then %do;
    _WeightLabel = symget('WeightLabel');
  %end;

  %if %length(&amp;amp;StatCol1) ne 0 %then %do;
    _StatColLabel1 = symget('SLabel1');
	_StatCol1 = &amp;amp;StatCol1;
  %end;

  %if %length(&amp;amp;StatCol2) ne 0 %then %do;
    _StatColLabel2 = symget('SLabel2');
	_StatCol2 = &amp;amp;StatCol2;
  %end;

  %if %length(&amp;amp;StatCol3) ne 0 %then %do;
    _StatColLabel3 = symget('SLabel3');
	_StatCol3 = &amp;amp;StatCol3;
  %end;

  %if %length(&amp;amp;StatCol4) ne 0 %then %do;
    _StatColLabel4 = symget('SLabel4');
	_StatCol4 = &amp;amp;StatCol4;
  %end;
 
  run;

/*--Reverse the order to avoid putting axis reverse--*/
proc sort data=_forest out=_forest;
  by descending _ObsId;
  run;

/*--Add sequence numbers to each observation--*/
data _forest;
  set _forest;
  studyvalue=_n_;
run;

/*--Output values and formatted strings to data set--*/
data _forestFormat;
  set _forest end=last;
  keep label start end fmtname type hlo;
  retain fmtname '_Study' type 'n';
  label=&amp;amp;Study;
  start=studyvalue;
  end=studyvalue;
  output;
  if last then do;
    hlo='O';
	label='Other';
	output;
  end;
  run;

/*--Create Format from data set--*/
proc format library=work cntlin=_forestFormat;
  run;

/*--Apply format to study values--*/
/*--Compute width of box proportional to weight in log scale--*/
data _forest;
  format studyvalue _study.;
  set _forest;
  %let Bands=%upcase(&amp;amp;Bands);
  %if &amp;amp;Bands eq YES or &amp;amp;Bands eq Y %then %do;
    if mod(studyvalue, 2) = 0 then _StudyRef=StudyValue;
  %end;
  run;

/*--Compute top and bottom offsets--*/
data _null_;
  pct=&amp;amp;Ratio/nobs;
  thk=pct* 0.9 *100;
  call symputx("pct", pct);
  call symputx("pct2", 2*pct);
  call symputx("RefThickness", thk);
  call symputx("count", nobs);
  set _forest nobs=nobs;
run;

/*title;*/
/*options nodate nonumber;*/

/*--Define GTL template for graph--*/
proc template;
  define statgraph ForestMacro;
    begingraph / designwidth=&amp;amp;Width designheight=&amp;amp;GraphHeight;
	  entrytitle "&amp;amp;Title";
	  entryfootnote halign=left "&amp;amp;FootNote";
	  %if %length(&amp;amp;title2) ne 0 %then %do;
	    entrytitle "&amp;amp;title2" / textattrs=graphLabelText;
      %end;
	  layout lattice / columns=3 columnweights=(&amp;amp;LabelColWidth &amp;amp;GraphColWidth &amp;amp;StatColWidth) columngutter=0
                       rowdatarange=union;
        /*--Column # 1 contains the Study Labels using Secondary Y axis--*/
        layout overlay / walldisplay=none x2axisopts=(display=none)
                         yaxisopts=(linearopts=(tickvaluesequence=(start=1 end=&amp;amp;count increment=1))
                                    offsetmin=&amp;amp;pct2 offsetmax=&amp;amp;pct display=none
                                    displaysecondary=(tickvalues &amp;amp;border));
		  scatterplot y=studyvalue x=_or1 / yaxis=Y xaxis=X2 markerattrs=(size=0) includemissinggroup=true;
		  scatterplot y=studyvalue x=_or1 / yaxis=Y xaxis=X2 markerattrs=(size=0) includemissinggroup=true;
		endlayout;
	    /*--Column # 2 contains the graph--*/
        layout overlay / &amp;amp;GraphWallDisplay border=false
                         xaxisopts=(offsetmin=0  type=log logopts=(minorticks=true)
                                    label="&amp;amp;PlotTitle" display=(ticks tickvalues line) 
                                    displaysecondary=(label &amp;amp;border)) 
                         yaxisopts=(linearopts=(tickvaluesequence=(start=1 end=&amp;amp;count increment=1))
                                    offsetmin=&amp;amp;pct2 offsetmax=&amp;amp;pct display=none);

		  /*--Draw alternating bands using referenceline--*/
          %if &amp;amp;Bands eq YES or &amp;amp;Bands eq Y %then %do;
            referenceline y=_StudyRef / lineattrs=(thickness=&amp;amp;RefThickness.PCT) datatransparency=0.9;
		  %end;

          /*--Draw Markers for SubGroup and Overall values--*/
		  %if %length(&amp;amp;Group) ne 0 %then %do;
            scatterplot y=studyvalue x=_or2 / markerattrs=(symbol=diamondfilled size=10) group=_grp 
                      includemissinggroup=true index=_grp;
		  %end;
          /*--Draw OddsRatio and Limits for Study Values--*/
          scatterplot y=studyvalue x=_or1 / xerrorupper=_ucl1 xerrorlower=_lcl1 
                  markerattrs=graphdata1(symbol=squarefilled size=&amp;amp;MarkerSize);

		  /*--Draw box representing the weight of the study--*/
          vectorplot y=studyvalue x=_x2 xorigin=_x1 yorigin=studyvalue / lineattrs=GraphData1(thickness=8) 
                 arrowheads=false;

          /*--Draw Reference lines and labels--*/
          referenceline x=1;
          referenceline x=0.01 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  referenceline x=0.1 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  referenceline x=10 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  referenceline x=100 /  lineattrs=(pattern=shortdash) datatransparency=0.5;
		  entry halign=left  "&amp;amp;Label1" / valign=bottom;
		  entry halign=right "&amp;amp;Label2" / valign=bottom;
		endlayout;

	    /*--Column # 2 contains the statistics data--*/
        layout overlay / &amp;amp;StatWallDisplay border=false
                         x2axisopts=(display=(tickvalues &amp;amp;border) displaysecondary=(line))
                         yaxisopts=(linearopts=(tickvaluesequence=(start=1 end=&amp;amp;count increment=1))
                                    offsetmin=&amp;amp;pct2 offsetmax=&amp;amp;pct 
                                    display=none &amp;amp;DisplaySecondary.);
          /*--Draw alternating bands using referenceline--*/
          %if &amp;amp;Bands eq YES %then %do;
            referenceline y=_StudyRef / lineattrs=(thickness=&amp;amp;RefThickness.PCT) datatransparency=0.9;
		  %end;

          /*--Draw standard statistics columns--*/
          %if &amp;amp;DisplayCols eq YES or &amp;amp;DisplayCols eq Y %then %do;
            scatterplot y=studyvalue x=_OddsRatioLabel / markercharacter=&amp;amp;OddsRatio xaxis=x2;
			scatterplot y=studyvalue x=_LowerLabel / markercharacter=&amp;amp;LCL xaxis=x2;
			scatterplot y=studyvalue x=_UpperLabel / markercharacter=&amp;amp;UCL xaxis=x2;
			%if &amp;amp;Weight ne %then %do;
              scatterplot y=studyvalue x=_WeightLabel / markercharacter=_wt xaxis=x2;
			%end;
		  %end;

		  /*--Draw additional statistics columns--*/
          %if %length(&amp;amp;StatCol1) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel1 / markercharacter=&amp;amp;StatCol1 xaxis=x2;
		  %end;

		  %if %length(&amp;amp;StatCol2) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel2 / markercharacter=&amp;amp;StatCol2 xaxis=x2;
		  %end;

          %if %length(&amp;amp;StatCol3) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel3 / markercharacter=&amp;amp;StatCol3 xaxis=x2;
		  %end;

          %if %length(&amp;amp;StatCol4) ne 0 %then %do;
            scatterplot y=studyvalue x=_StatColLabel4 / markercharacter=&amp;amp;StatCol4 xaxis=x2;
		  %end;

		endlayout;
	  endlayout;
	endgraph;
  end;
run;

proc sgrender data=_forest template=ForestMacro description='Forest Plot';
  run;

%finished:
%mend ForestMacro;
*++++++++++++++++++++++++++++++++++++++++++++++++++++
End of Macro
++++++++++++++++++++++++++++++++++++++++++++++++++++;

data class ;
	set sashelp.class ;
 if _n_ &amp;lt;=4 then do;
 *Creating lcl negative values  and affecting the x axis in macro;
	  HR=0.042;
	  lcl=HR-0.052;
	  ucl=HR+0.01;
	  name1 = name||"its long name";
	  pvalue=0.019;

  end;
  else if _n_ &amp;gt;=5 and _n_&amp;lt;=9 then do;
	  HR=0.083;
	  lcl=HR-0.02;
	  ucl=HR+0.1;
	  name1=name;
	  pvalue=0.089;

  end;

  else if _n_ &amp;gt;=10 and _n_&amp;lt;=15 then do;
	  HR=0.346;
	  lcl=HR-0.11;
	  ucl=HR+0.3;
	  name1=name;
	  pvalue=0.004;

  end;

  else   do;
	  HR=0.449;
	  lcl=HR-0.21;
	  ucl=HR+0.3;
	  name1=name;
	  pvalue=0.45;
  end;

  Groupid=1;
 keep  hr ucl name1 lcl pvalue groupid;
run;

%ForestMacro(data=class, Study=name1, Group=GroupId, OddsRatio=HR,
LCL=lcl, UCL=ucl,Bands=NO, GraphWalls=NO, StatWalls=NO, Borders=NO, StatCol1=pvalue);



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Reference Macro link:&amp;nbsp;&lt;A href="https://support.sas.com/kb/43/855.html" target="_blank" rel="noopener"&gt;https://support.sas.com/kb/43/855.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 22:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837296#M23193</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-06T22:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem Forest Plot X - axis control with negative LCL Values using SAS %forestmacro</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837297#M23194</link>
      <description>Odds ratio have be above 0 by definition don't they? Are you plotting a different statistics?&lt;BR /&gt;If not, you may want to use a newer method. &lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2016/05/30/ctspedia-clinical-graphs-subgrouped-forest-plot/" target="_blank"&gt;https://blogs.sas.com/content/graphicallyspeaking/2016/05/30/ctspedia-clinical-graphs-subgrouped-forest-plot/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;You'll have a lot more control with SGPLOT and the Axistables options.</description>
      <pubDate>Thu, 06 Oct 2022 22:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837297#M23194</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-06T22:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem Forest Plot X - axis control with negative LCL Values using SAS %forestmacro</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837298#M23195</link>
      <description>&lt;P&gt;You are correct, I was using the graph for risk difference where there is a chance of having negative values, I thought this macro will work with little modifications since most of the other settings are there as per my requirement. But&amp;nbsp; it looks like the macro controlled based on the Odds ratio values like you mentioned. Thank you for pointing out for this and guideing for another program. I will take a look and work on it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 22:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837298#M23195</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-06T22:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem Forest Plot X - axis control with negative LCL Values using SAS %forestmacro</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837302#M23196</link>
      <description>&lt;P&gt;Nothing to do with the LCL, AXIS or such.&lt;/P&gt;
&lt;P&gt;In this example at least.&lt;/P&gt;
&lt;P&gt;It is your code assigning values to the variable _or2.&lt;/P&gt;
&lt;P&gt;Your Class example data set only has values of 1 for the Groupid variable. So the code where -or2 is assigned &lt;STRONG&gt;the first time you create the _forest data set&lt;/STRONG&gt;:&lt;/P&gt;
&lt;PRE&gt;  /*--Group=2 &amp;amp; 3 (SubGroup and Overall) values will be drawn with groupindex=2 &amp;amp; 3--*/
    else if &amp;amp;group &amp;gt; 1 then do;
      _grp=&amp;amp;group;
      _or2 = &amp;amp;OddsRatio;
    end;
&lt;/PRE&gt;
&lt;P&gt;Never executes as &amp;amp;group, which uses GroupId variable, is never greater than 1 so _or2 is always missing.&lt;/P&gt;
&lt;P&gt;So any attempt to use variable where it needs at least one non-missing value will fail.&lt;/P&gt;
&lt;P&gt;The code that attempts to verify whether the plot for _or2 should be done tests for the Presences of &amp;amp;group, not the values involved that are required to create _or2.&lt;/P&gt;
&lt;PRE&gt;		  %if %length(&amp;amp;Group) ne 0 %then %do;
            scatterplot y=studyvalue x=_or2 / markerattrs=(symbol=diamondfilled size=10) group=_grp 
                      includemissinggroup=true index=_grp;
		  %end;
&lt;/PRE&gt;
&lt;P&gt;So maybe in the code that assigns _or2 values a macro variable that will indicate at least one value was set should be created and used in the above %if. Personally I would probably test for a specific value instead of presence with should be known flag value set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I find multiple places where you replace your _forest data set. That can be very hard to debug in general and when buried in a macro even worse as to exactly which step created any problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 23:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837302#M23196</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-06T23:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem Forest Plot X - axis control with negative LCL Values using SAS %forestmacro</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837305#M23199</link>
      <description>&lt;P&gt;Thank you for guiding me.&amp;nbsp; I think I didn't paid that much attention inside the macro. I will work to debug on it and change the dataset names ( this was a sas macro so I did not attempted anything to change in macro before). When kept the LCL as positive values , the graphs looked fine but I did not paid the the attention in log. so&amp;nbsp; I guess it happening in both cases.&amp;nbsp; I will look into this more. Thanks again for your time.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 23:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Problem-Forest-Plot-X-axis-control-with-negative-LCL-Values/m-p/837305#M23199</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-06T23:28:47Z</dc:date>
    </item>
  </channel>
</rss>

