FULL SAS CODE TO PRODUCE A NICE FOREST PLOT

Link

This code summarizes the steps described in the article :  “Let’s go for a walk in the forest!”

/***Create the survival dataset ***/
data bone_marrow;
  input grp t1 t2 dind rind dfree ta aind tc cind tp pind age dage sex dsex cmv dcmv wait fab
        hosp mtx; 
  label grp = "Disease Group"
      t1 = "Time To Death Or On Study Time"
	  T2 = "Disease Free Survial Time"
      dind = "Death indicator"
	  rind = "Relapse indicator"
	  dfree = "Disease Free Survial"
	  ta = "Time to Acute GVHD"
	  aind = "Acute GVHD indicator"
	  tc = "Time to chronic GVHD"
	  cind = "Chronic GVHD indicator"
	  tp = "Time to normal Platelets"
	  pind = "Platelet Recovery Indicator"
	  age = "Patient Age"
	  dage = "Donor Age"
	  sex = "Patient sex"
	  dsex = "Donor Sex"
	  cmv = "Patient CMV Status"
	  dcmv = "Donor CMV"
	  wait = "Waiting time: days"
	  fab = "FAB"
	  hosp = "Hospital"
	  mtx = "MTX";
datalines;
1  2081  2081  0  0  0    67  1   121  1    13  1  26  33  1  0  1  1    98  0  1  0
1  1602  1602  0  0  0  1602  0   139  1    18  1  21  37  1  1  0  0  1720  0  1  0
1  1496  1496  0  0  0  1496  0   307  1    12  1  26  35  1  1  1  0   127  0  1  0
1  1462  1462  0  0  0    70  1    95  1    13  1  17  21  0  1  0  0   168  0  1  0
1  1433  1433  0  0  0  1433  0   236  1    12  1  32  36  1  1  1  1    93  0  1  0
1  1377  1377  0  0  0  1377  0   123  1    12  1  22  31  1  1  1  1  2187  0  1  0
1  1330  1330  0  0  0  1330  0    96  1    17  1  20  17  1  0  1  1  1006  0  1  0
1   996   996  0  0  0    72  1   121  1    12  1  22  24  1  0  0  0  1319  0  1  0
1   226   226  0  0  0   226  0   226  0    10  1  18  21  0  1  0  0   208  0  1  0
1  1199  1199  0  0  0  1199  0    91  1    29  1  24  40  1  1  0  1   174  0  3  1
1  1111  1111  0  0  0  1111  0  1111  0    22  1  19  28  1  1  0  1   236  0  3  1
1   530   530  0  0  0    38  1    84  1    34  1  17  28  1  1  0  0   151  0  3  1
1  1182  1182  0  0  0  1182  0   112  1    22  1  24  23  0  0  0  1   203  0  2  1
1  1167  1167  0  0  0    39  1   487  1  1167  0  27  22  0  1  1  1   191  0  2  1
1   418   418  1  0  1   418  0   220  1    21  1  18  14  1  1  0  0   110  0  1  0
1   417   383  1  1  1   417  0   417  0    16  1  15  20  1  1  0  0   824  0  1  0
1   276   276  1  0  1   276  0    81  1    21  1  18   5  0  0  0  0   146  0  1  0
1   156   104  1  1  1    28  1   156  0    20  1  20  33  1  1  0  1    85  0  1  0
1   781   609  1  1  1   781  0   781  0    26  1  27  27  1  0  1  1   187  0  1  0
1   172   172  1  0  1    22  1   172  0    37  1  40  37  0  0  0  1   129  0  1  0
1   487   487  1  0  1   487  0    76  1    22  1  22  20  1  1  0  0   128  0  1  0
1   716   662  1  1  1   716  0   716  0    17  1  28  32  1  1  0  0    84  0  1  0
1   194   194  1  0  1   194  0    94  1    25  1  26  32  0  1  0  0   329  0  1  0
1   371   230  1  1  1   371  0   184  1     9  1  39  31  0  1  0  1   147  0  1  0
1   526   526  1  0  1   526  0   121  1    11  1  15  20  1  1  0  0   943  0  1  0
1   122   122  1  0  1    88  1   122  0    13  1  20  26  1  0  0  1  2616  0  1  0
1  1279   129  1  1  1  1279  0  1279  0    22  1  17  20  0  0  0  0   937  0  3  1
1   110    74  1  1  1   110  0   110  0    49  1  28  25  1  0  1  0   303  0  3  1
1   243   122  1  1  1   243  0   243  0    23  1  37  38  0  1  1  1   170  0  3  1
1    86    86  1  0  1    86  0    86  0    86  0  17  26  1  0  1  0   239  0  3  1
1   466   466  1  0  1   466  0   119  1   100  1  15  18  1  1  0  0   508  0  3  1
1   262   192  1  1  1    10  1    84  1    59  1  29  32  1  1  1  0    74  0  3  1
1   162   109  1  1  1   162  0   162  0    40  1  36  43  1  1  1  0   393  0  2  1
1   262    55  1  1  1   262  0   262  0    24  1  23  16  0  1  1  1   331  0  2  1
1     1     1  1  0  1     1  0     1  0     1  0  42  48  1  1  0  0   196  0  2  1
1   107   107  1  0  1   107  0   107  0   107  0  30  19  1  1  1  1   178  0  2  1
1   269   110  1  1  1   269  0   120  1    27  1  29  20  0  1  1  1   361  0  2  1
1   350   332  1  0  1   350  0   350  0    33  1  22  20  1  0  0  0   834  0  2  1
2  2569  2569  0  0  0  2569  0  2569  0    21  1  19  13  1  1  1  0   270  1  1  0
2  2506  2506  0  0  0  2506  0  2506  0    17  1  31  34  1  1  0  0    60  0  1  0
2  2409  2409  0  0  0  2409  0  2409  0    16  1  35  31  1  1  1  1   120  0  1  0
2  2218  2218  0  0  0  2218  0  2218  0    11  1  16  16  1  1  1  0    60  1  1  0
2  1857  1857  0  0  0  1857  0   260  1    15  1  29  35  0  0  1  0    90  0  1  0
2  1829  1829  0  0  0  1829  0  1829  0    19  1  19  18  1  1  1  0   210  0  1  0
2  1562  1562  0  0  0  1562  0  1562  0    18  1  26  30  1  1  1  1    90  0  1  0
2  1470  1470  0  0  0  1470  0   180  1    14  1  27  34  1  1  0  1   240  0  1  0
2  1363  1363  0  0  0  1363  0   200  1    12  1  13  24  1  1  1  0    90  0  1  0
2  1030  1030  0  0  0  1030  0   210  1    14  1  25  29  0  0  0  0   210  0  1  0
2   860   860  0  0  0   860  0   860  0    15  1  25  31  0  1  0  1   180  0  1  0
2  1258  1258  0  0  0  1258  0   120  1    66  1  30  16  0  1  1  0   180  0  2  1
2  2246  2246  0  0  0    52  1   380  1    15  1  45  39  0  0  0  0   105  0  4  0
2  1870  1870  0  0  0  1870  0   230  1    16  1  33  30  0  0  1  1   225  0  4  0
2  1799  1799  0  0  0  1799  0   140  1    12  1  32  23  1  0  0  0   120  0  4  0
2  1709  1709  0  0  0    20  1   348  1    19  1  23  28  0  1  1  0    90  1  4  0
2  1674  1674  0  0  0  1674  0  1674  0    24  1  37  34  1  1  0  0    60  1  4  0
2  1568  1568  0  0  0  1568  0  1568  0    14  1  15  19  1  0  0  0    90  0  4  0
2  1527  1527  0  0  0  1527  0  1527  0    13  1  22  12  0  1  0  1   450  1  4  0
2  1324  1324  0  0  0    25  1  1324  0    15  1  46  31  1  1  1  1    75  0  4  0
2   957   957  0  0  0   957  0   957  0    69  1  18  17  1  1  0  0    90  0  4  0
2   932   932  0  0  0    29  1   932  0     7  1  27  30  0  0  0  0    60  1  4  0
2   847   847  0  0  0   847  0   847  0    16  1  28  29  1  1  0  0    75  0  4  0
2   848   848  0  0  0   848  0   155  1    16  1  23  26  1  1  0  0   180  0  4  0
2  1850  1850  0  0  0  1850  0  1850  0     9  1  37  36  0  0  0  1   180  0  3  1
2  1843  1843  0  0  0  1843  0  1843  0    19  1  34  32  0  0  1  1   270  0  3  1
2  1535  1535  0  0  0  1535  0  1535  0    21  1  35  32  0  1  0  0   180  1  3  1
2  1447  1447  0  0  0  1447  0   220  1    24  1  33  28  0  1  1  1   150  0  3  1
2  1384  1384  0  0  0  1384  0   200  1    19  1  21  18  0  0  0  0   120  0  3  1
2   414   414  1  0  1   414  0   414  0    27  1  21  15  1  1  0  1   120  1  1  0
2  2204  2204  1  0  1  2204  0  2204  0    12  1  25  19  0  0  0  1    60  0  1  0
2  1063  1063  1  0  1  1063  0   240  1    16  1  50  38  1  0  1  0   270  1  1  0
2   481   481  1  0  1    30  1   120  1    24  1  35  36  1  0  1  1    90  1  1  0
2   105   105  1  0  1    21  1   105  0    15  1  37  34  1  0  1  1   120  0  1  0
2   641   641  1  0  1   641  0   641  0    11  1  26  24  1  1  0  0    90  0  1  0
2   390   390  1  0  1   390  0   390  0    11  1  50  48  1  1  0  0   120  0  1  0
2   288   288  1  0  1    18  1   100  1   288  0  45  43  1  1  1  1    90  0  1  0
2   522   421  1  1  1    25  1   140  1    20  1  28  30  1  1  0  1    90  1  1  0
2    79    79  1  0  1    16  1    79  0    79  0  43  43  0  0  0  0    90  0  1  0
2  1156   748  1  1  1  1156  0   180  1    18  1  14  19  1  0  0  0    60  0  1  0
2   583   486  1  1  1   583  0   583  0    11  1  17  14  0  1  0  0   120  0  1  0
2    48    48  1  0  1    48  0    48  0    14  1  32  33  0  1  1  0   150  1  1  0
2   431   272  1  1  1   431  0   431  0    12  1  30  23  0  1  1  0   120  1  1  0
2  1074  1074  1  0  1  1074  0   120  1    19  1  30  32  1  1  1  0   150  1  1  0
2   393   381  1  1  1   393  0   100  1    16  1  33  28  0  0  0  0   120  1  1  0
2    10    10  1  0  1    10  0    10  0    10  0  34  54  1  0  1  1   240  0  2  1
2    53    53  1  0  1    53  0    53  0    53  0  33  41  0  1  1  1   180  0  2  1
2    80    80  1  0  1    10  1    80  0    80  0  30  35  0  0  0  1   150  0  2  1
2    35    35  1  0  1    35  0    35  0    35  0  23  25  0  1  1  1   150  0  2  1
2  1499   248  0  1  1  1499  0  1499  0     9  1  35  18  1  1  0  1    30  0  4  0
2   704   704  1  0  1    36  1   155  1    18  1  29  21  0  1  1  0   105  0  4  0
2   653   211  1  1  1   653  0   653  0    23  1  23  16  1  0  0  0    90  1  4  0
2   222   219  1  1  1   222  0   123  1    52  1  28  30  1  1  1  1   120  1  3  1
2  1356   606  0  1  1  1356  0  1356  0    14  1  33  22  1  1  1  0   210  1  3  1
3  2640  2640  0  0  0  2640  0  2640  0    22  1  18  23  1  1  0  0   750  0  1  0
3  2430  2430  0  0  0  2430  0  2430  0    14  1  29  26  1  1  0  1    24  0  1  0
3  2252  2252  0  0  0  2252  0   150  1    17  1  35  31  1  0  0  0   120  0  1  0
3  2140  2140  0  0  0  2140  0   220  1    18  1  27  17  1  1  1  1   210  0  1  0
3  2133  2133  0  0  0  2133  0   250  1    17  1  36  39  0  1  0  0   240  0  1  0
3  1238  1238  0  0  0  1238  0   250  1    18  1  24  28  1  0  1  1   240  0  1  0
3  1631  1631  0  0  0  1631  0   150  1    40  1  27  21  1  0  1  0   690  1  2  1
3  2024  2024  0  0  0  2024  0   180  1    16  1  35  41  0  1  0  0   105  1  4  0
3  1345  1345  0  0  0    32  1   360  1    14  1  50  36  1  1  1  1   120  0  4  0
3  1136  1136  0  0  0  1136  0   140  1    15  1  47  27  1  0  1  0   900  0  3  1
3   845   845  0  0  0   845  0   845  0    20  1  40  39  0  0  1  1   210  1  3  1
3   491   422  1  1  1   491  0   180  1   491  0  22  21  0  0  0  0   210  1  1  0
3   162   162  1  0  1   162  0   162  0    13  1  22  23  1  0  0  1   300  0  1  0
3  1298    84  1  1  1  1298  0  1298  0  1298  0   8   2  0  0  1  0   105  1  1  0
3   121   100  1  1  1    28  1   121  0    65  1  39  48  1  1  1  1   210  1  1  0
3     2     2  1  0  1     2  0     2  0     2  0  20  19  1  1  0  0    75  1  1  0
3    62    47  1  1  1    62  0    62  0    11  1  27  25  1  1  0  0    90  1  1  0
3   265   242  1  1  1   265  0   210  1    14  1  32  32  1  0  0  0   180  1  1  0
3   547   456  1  1  1   547  0   130  1    24  1  31  28  1  0  1  1   630  1  1  0
3   341   268  1  1  1    21  1   100  1    17  1  20  23  0  1  1  1   180  1  1  0
3   318   318  1  0  1   318  0   140  1    12  1  35  40  0  1  1  1   300  0  1  0
3   195    32  1  1  1   195  0   195  0    16  1  36  39  1  1  0  0    90  1  1  0
3   469   467  1  1  1   469  0    90  1    20  1  35  33  0  0  1  0   120  0  1  0
3    93    47  1  1  1    93  0    93  0    28  1   7   2  1  1  0  0   135  1  1  0
3   515   390  1  1  1   515  0   515  0    31  1  23  25  1  1  1  0   210  1  1  0
3   183   183  1  0  1   183  0   130  1    21  1  11  7  0  1  0  0    120  1  1  0
3   105   105  1  0  1   105  0   105  0   105  0  14  18  1  0  0  0   150  1  1  0
3   128   115  1  1  1   128  0   128  0    12  1  37  35  0  0  1  1   270  0  1  0
3   164   164  1  0  1   164  0   164  0   164  0  19  32  0  0  0  1   285  1  1  0
3   129    93  1  1  1   129  0   129  0    51  1  37  34  0  1  1  0   240  1  1  0
3   122   120  1  1  1   122  0   122  0    12  1  25  29  0  1  1  1   510  1  1  0
3    80    80  1  0  1    21  1    80  0     0  1  35  28  1  0  0  0   780  1  1  0
3   677   677  1  0  1   677  0   150  1     8  1  15  14  1  1  1  0   150  1  1  0
3    73    64  1  1  1    73  0    73  0    38  1  45  42  0  1  1  0   180  1  2  1
3   168   168  1  0  1   168  0   200  1    48  1  32  43  0  1  1  1   150  1  2  1
3    74    74  1  0  1    29  1    74  0    24  1  41  29  0  1  1  1   750  0  2  1
3    16    16  1  0  1    16  0    16  0    16  0  27  36  0  0  1  0   180  0  4  0
3   248   157  1  1  1   248  0   100  1    52  1  33  39  0  0  1  1   180  1  4  0
3   732   625  1  1  1   732  0   732  0    18  1  39  43  0  1  1  1   150  1  4  0
3   105    48  1  1  1   105  0   105  0    30  1  17  14  0  1  0  0   210  1  4  0
3   392   273  1  1  1   392  0   122  1    24  1  43  50  1  1  1  0   240  0  3  1
3    63    63  1  0  1    38  1    63  0    16  1  44  37  1  1  0  0   360  1  3  1
3    97    76  1  1  1    97  0    97  0    97  0  48  56  1  1  1  1   330  0  3  1
3   153   113  1  1  1   153  0   153  0    59  1  31  25  0  1  1  1   240  0  3  1
3   363   363  1  0  1   363  0   363  0    19  1  52  48  1  1  1  0   180  0  3  1
;
run;

proc format;
  VALUE  grp  1 = "ALL"
            2 = "AML Low Risk"
            3 = "AML High Risk" ;
  value dind  0 = "Alive"
              1 = "Dead";
  value rind  0 = "Disease Free"
              1 = "Relapsed";
  value dfree 0 = "Alive Disease Free"
              1 = "Dead or Relapsed";
  value aind  0 = "Never Developed Acute GVHD"
              1 = "Developed Acute GVHD";
  value cind  0 = "Never Developed Chronic GVHD"
              1 = "Developed Chronic GVHD";
  value pind  0 = "Platelet Never Returned to Normal"
              1 = "Returned to Normal";
  value sex   0 = "Female"
              1 = "Male";
  value dsex  0 = "Female"
              1 = "Male";
  value cmv   0 = "CMV Negative"
              1 = "CMV Positive";
  value dcmv  0 = "CMV Negative"
              1 = "CMV Positive";
  value fab   0 = "Otherwise"
              1 = "FAB Grade 4 or 5 and AML";
  value hosp  1 = "Ohio State Univ"
              2 = "Alferd"
              3 = "St. Vincent"
              4 = "Hahnemann";
  value mtx   0 = "No"
              1 = "Yes";
proc print; run;

data bm;
	set bone_marrow;
/***create a censor variable ***/
os=t1;
if dind in (1) then censor=1;
else censor=0;
format grp grp. dind dind. rind rind. dfree dfree. aind aind. cind cind. pind pind. sex sex. dsex dsex. cmv cmv. dcmv dcmv.
fab fab. hosp hosp. mtx mtx.;
run;


%macro ph (var=,out=,param=,ref=,fmt=,ord=);
proc sort data=bm; by  &var; run;
proc phreg data=bm;
    by  &var;
    class &var mtx;
	model os*censor (0)=  &var mtx/ ties=efron risklimits ;
	ods output ParameterEstimates=&out._para;
run;

proc phreg data=bm;
    class &var (ref="&ref");
	model os*censor (0)=  &var / ties=efron risklimits ;
	ods output ModelANOVA=&out._pval ;
run;

proc sort data=bm; by  &var; run;
ods select none;
ods output  productlimitestimates=rate ;
proc lifetest data= bm outsurv=_surv;
    by &var;
	time os*censor (0);
	strata mtx;
run;
ods select all;

proc sort data=rate  out=rates (where=(SURVIVAL ne .)); by &var stratum os; run;
data rates1;
	set rates;
	by &var stratum os;
	if last.&var or last.stratum;
	pct=STRIP(PUT(FAILURE*100,8.1));
	order=⩝
	keep order pct stratum &var ;
run;

proc sort data=rates1; by order &var; run;
proc transpose data=rates1  out=rates2 ;
	by order &var;
	id stratum;
	var pct;
run;

data &out._para1;
set &out._para;
	ci=strip(put(HazardRatio,8.2))||' '||catx(catx(' ; ',put(HRLowerCL ,8.2),put(HRUpperCL,8.2)),'(',')');
order=⩝
effect=&var;
keep order ci effect &var;
run;

data &out._pval1;
set &out._pval;
pval=strip(put(ProbChiSq,pvalue5.3));
order=⩝
keep order pval;
run;

 data bms;
	set bm;
	sno=_n_ ;
run;

proc sql;
	create table cnt as
	select 'cnt' as cnt, &var, count (sno) as N
	from bms  
	group by &var
	order by &var;
	create table cntall as
	select 'cnt' as cnt, count (sno) as N_
	from bms  
	 ;
;quit;

data cntf;
	merge cnt(in=a) cntall(in=b) ;
	by cnt;
	pct=STRIP(PUT(n,BEST.))||" ("||COMPRESS(PUT(n/n_*100,8.1))||" )";
	order=⩝
run;

proc sort data=cntf; by order &var; run;
proc transpose data=cntf  out=cntfn ;
	by order &var;
	id cnt;
	var pct;
run;

proc sort data=&out._para1; by  order &var; run;
proc sort data=rates2; by  order &var; run;
proc sort data=cntfn; by  order &var; run;
data &out._para2;
 merge &out._para1  rates2 (keep=order &var _1 _2) cntfn(drop=_name_);
 by  order &var;
 run;

 data &out(drop=&var);
 merge &out._para2  &out._pval1;
 by  order ;
	param="&param";
	cat=strip(put(effect,&fmt));
		if not first.order then do ;pval='';end;
run;
%mend;

%ph (var= grp, out= _6_fin,param=%nrstr(AML Group),fmt=grp.,ref=ALL,ord=6);
%ph (var= dsex, out= _1_fin,param=%nrstr(Gender),fmt=dsex.,ref=Male,ord=1);

%ph (var= aind, out= _2_fin,param=%nrstr(Acute GVHD),fmt=aind.,ref=Never Developed Acute GVHD,ord=2);
%ph (var= cind, out= _3_fin,param=%nrstr(Chronic GVHD),fmt=cind.,ref =Never Developed Chronic GVHD,ord=3);

%ph (var= dcmv, out= _4_fin,param=%nrstr(Cytomegalovirus),fmt=dcmv.,ref=CMV Negative,ord=4);
%ph (var= fab, out= _5_fin,param=%nrstr(FAB Grade),fmt=fab.,ref=Otherwise,ord=5);

data allset ;
length param cat $200.;
set 
	_1_fin  
	_2_fin 
	_3_fin
	_4_fin
	_5_fin  
	_6_fin 
;run;

data add;
length param $200.;
	param='Gender';order=0.5 ; output;
	param='Acute GVHD';order=1.5 ; output;
	param='Chronic GVHD';order=2.5 ; output;
	param='Cytomegalovirus';order=3.5 ; output;
	param='FAB Grade';order=4.5 ; output;
	param='AML Group';order=5.5 ; output;
run;

data all;
	length param $200.;
	set allset add;
	if cat notin ('') then param = cat;
run;


proc sort data=all ; by order ; run;
data allf (rename=(order =ord1 param=_name_));
	set all;
	keep order ci pval param _1 _2 cnt;
run;

data allfi;
length _NAME_ $200.;
set allf;
	if ci notin ('') then indent= 1;
	else indent=0;
	if ci notin ('') then id= 0;
	else id=1;
	mean=input(scan(ci,1,"("),best.);
	low=input(scan(scan(ci,1,";"),2,"("),best.);
	high=input(scan(scan(ci,2,";"),1,")"),best.);
	zero=0;
  val=mod(_N_-1, 6);
  if val ne . then ref=_name_;
run;

proc sql;
	create table allfin as
	select 
           _name_ as Subgroup label='Parameter',
           _name_ as order label='Parameter',
           _1 as mtx label='MTX',_2 as plc label='Placebo',cnt label='No of patients (%)',
           indent,mean Label=".",low,high,zero,pval as pvalue label="  P-value",
           ci as hzratio label="Hazard Ratio ",monotonic() as val,id,ref
	from allfi 
    ;
quit;

data allfina;
set allfin;
/* Determine the marker size based on population size */
SquareSize = (input(scan(cnt,1,'('),best.)/3000) * 12 ;
  if val in (1 4 7 10 16) then ref='';
run;


/*--Modify font style for axis label, value and data--*/
proc template;
  define style listingSF; 
    parent = Styles.HTMLBlue; 
    style GraphFonts from GraphFonts                                                      
      "Fonts used in graph styles" /                                       
      'GraphDataFont' = ("<sans-serif>, <MTsans-serif>",8.5pt)                                
      'GraphValueFont' = ("<sans-serif>, <MTsans-serif>",9pt)
      'GraphLabelFont' = ("<sans-serif>, <MTsans-serif>",10pt); 
  end;
run;

/*--Define templage for Forest Plot--*/
/*--Template uses a Layout Lattice of 5 columns--*/
proc template;
  define statgraph ForestPlot;
  dynamic _headercolor _color _thk;
    begingraph;
      entrytitle halign=center textattrs=(size=10 )'Impact of Treatment on Overall Survival by Subgroup ';
      entrytitle halign=center textattrs=(size=8) 'Hazard Ratio and 95% CL';
      discreteattrmap name='text';
        value '0' / textattrs=(weight=bold);
        value other;
      enddiscreteattrmap;
      discreteattrvar attrvar=type var=indent attrmap='text';
      layout lattice / columns=5 columnweights=(0.25 0.15 0.35 0.15 0.1);

      /*--Column headers--*/
      sidebar / align=top;
        layout lattice / rows=2 columns=5 columnweights=(0.25 0.15 0.35 0.15 0.1)
           opaque=true backgroundcolor=_headercolor;
           entry textattrs=(size=8) halign=left "";
          entry textattrs=(size=8) halign=left "";
          entry textattrs=(size=8) halign=left "";
          entry textattrs=(size=8) halign=left "";
          entry textattrs=(size=8) halign=left "";
         entry textattrs=(size=8  weight=bold) halign=left "Subgroup";
          entry textattrs=(size=8  weight=bold) halign=left "No of patients (%)";
          entry textattrs=(size=8  weight=bold) halign=left " ";
          entry textattrs=(size=8  weight=bold) halign=left "Hz ratio (95%CI)";
          entry textattrs=(size=8  weight=bold) halign=left "P-value";

        endlayout;
      endsidebar;

       /*--First Subgroup column, shows only the Y2 axis--*/
      layout overlay / walldisplay=none xaxisopts=(reverse=true  display=none ) 
          yaxisopts=(reverse=true display=none tickvalueattrs=(weight=bold)
                      );
        referenceline y=ref / lineattrs=(thickness=_thk color=_color);
        axistable y=subgroup value=order /display=(values) indentweight=indent textgroup=type;
       endlayout;

       /*--Second column showing Count and percent--*/
       layout overlay /   halign=center
            yaxisopts=(reverse=true display=none) walldisplay=none;
         referenceline y=ref / lineattrs=(thickness=_thk color=_color);
         axistable y=subgroup value=cnt/display=(values);
       endlayout;

       /*--Third column showing HR ratio graph--*/
       layout overlay / 
           xaxisopts=(
                      label='<--Placebo Better----                ----MTX Better--> '  
                      labelattrs=(weight=bold color=black size=8) 
                      type=log logopts=( viewmin=0.1 viewmax=5.0)
                      )
           yaxisopts=(reverse=true display=none) walldisplay=none;

         referenceline y=ref / lineattrs=(thickness=_thk color=_color);
         scatterplot y=subgroup x=mean / xerrorlower=low xerrorupper=high 
           markerattrs=(symbol=squarefilled) sizeresponse=SquareSize sizemin=4 sizemax=12;
         referenceline x=1;
         endlayout;

		/*--Fourth column showing HR ratio values--*/
       layout overlay /   halign=right
            yaxisopts=(reverse=true display=none) walldisplay=none;
         referenceline y=ref / lineattrs=(thickness=_thk color=_color);
         axistable y=subgroup value=hzratio/ display=(values) valuehalign=right showmissing=false;
       endlayout;

	    /*--Fifth column showing P-Values--*/
       layout overlay /   halign=right
            yaxisopts=(reverse=true display=none) walldisplay=none;
         referenceline y=ref / lineattrs=(thickness=_thk color=_color);
         axistable y=subgroup value=pvalue/ display=(values) valuehalign=center valuejustify=right showmissing=false ;
       endlayout;

     endlayout;
     entryfootnote halign=left textattrs=(size=6) 
       'The p-value is from the test statistic for testing the interaction between the '
       'treatment and any subgroup variable';
   endgraph;
  end;
run;


%let dpi=300;
%let w=8in;
%let h=6in;
/*----Create Graph-----*/
ods listing style=listingSF gpath="C:\Path_Image\output" image_dpi=&dpi;
ods graphics / reset noscale width=&w height=&h imagename='ForestPlot' imagefmt=png;
proc sgrender data=allfina template=Forestplot;
/*----Define thickness and header/row colour-----*/
dynamic _headercolor='cxffffff' _color='cxffffff' _thk=12 ;
run;

ods listing close;