%Let Pgm=utl_LynUp; /*--------------------------*\ | Line up decimal in | | proc report | | Create Data | \*--------------------------*/ proc template; define style LineUp; parent=styles.rtf; * note: use 10.1 font not 10 to get around ODS bug in v8.2; replace fonts / 'TitleFont2' = ("Arial",12pt,Normal) 'TitleFont' = ("Arial",12pt,Normal) 'StrongFont' = ("Arial",10.1pt) 'EmphasisFont' = ("Arial",10.1pt) 'headingEmphasisFont' = ("Arial",10.1pt) 'headingFont' = ("Arial",10.1pt) 'docFont' = ("Arial",10.1pt) 'EmphasisFont' = ("Arial",10.1pt) 'FixedEmphasisFont' = ("Courier",9pt) 'FixedStrongFont' = ("Courier",9pt) 'FixedHeadingFont' = ("Courier",9pt) 'BatchFixedFont' = ("Courier",6.7pt) 'FixedFont' = ("Courier",9pt); style table from table / rules=groups frame=box cellpadding = 2pt cellspacing = 2pt borderwidth = 0.5pt; replace Body from Document / bottommargin = 1in topmargin = 1in rightmargin = 1in leftmargin = 1.25in; replace HeadersAndFooters from Cell / font = fonts('docFont') foreground = colors('datafg') background = colors('databg') protectspecialchars=off; replace SystemFooter from TitlesAndFooters / font = fonts('docFont') just = L; end; run; quit; Data MkeDat; Do Trt= 'Placebo', 'Potion7', 'Potion8', 'Potion9'; Do PatNum=1 to 90; If normal(-1) < .5 then Rce='White'; Else Rce='Black'; If normal(-1) < .6 then Cty='Europe'; Else Cty='USA'; If normal(-1) < .7 then Ins='Uninsured'; Else Ins='Insured'; If normal(-1) < .4 then Sex='Female'; Else Sex='Male'; Dia = abs(int(150 +30*normal(-1))); Sys = Abs(int(190 +30*normal(-1))); Age=Abs(Int ( 50 + 10* normal(-1))); Wgt=Abs(Int ( 40 + 10* normal(-1))); Hgt=Abs(round(1.5 + .25 * normal(-1),.1)) ; If normal(-1) < .7 then output; End; End; Stop; Run; Proc sql; Create Table MkeStaTisTic(drop=Nul) as Select /* Header into mac vars */ resolve('%let '!! Trt !!'='!!Trt!!'\-2n(N='!!put( Count(*),2.)!!');') as Nul, %Macro AveStdMinMax(Var); Put(Mean(&Var.),5.1) as &Var.Ave, Put(Std(&Var.),5.1) as &Var.Std, '('!!Put(Min(&Var.),5.1)!!','!!Put(Max(&Var.),5.1)!!')' as &Var.Xmn, %Mend AveStdMinMax; %AveStdMinMax(Age) %AveStdMinMax(Hgt) %AveStdMinMax(Wgt) %AveStdMinMax(Dia) %AveStdMinMax(Sys) %Macro FrqPct(var,cat1,cat2); Put(Sum(&Var.="&cat1."),5.2)!!'('!!put(100*Sum(&Var.="&cat1.")/Count(*),5.1)!!'%)' as %substr(&cat1.,1,3)Pct, Put(Sum(&Var.="&cat2."),5.2)!!'('!!put(100*Sum(&Var.="&cat2.")/Count(*),5.1)!!'%)' as %substr(&cat2.,1,3)Pct, %Mend FrqPct; %FrqPct(Sex,Male,Female) %FrqPct(Cty,USA,Europe) %FrqPct(Rce,Black,White) %FrqPct(Ins,Insured,Uninsured) Trt From MkeDat Group By Trt ; quit; run; %Put Placebo= &Placebo. Potion7= &Potion7. Potion8= &Potion8. Potion9= &Potion9.; Data MkeRow(Keep=Trt Cat Typ Val); Length Typ $3 Cat $3 Val $32 spa $8; Set MkeStaTisTic; %Macro TypVal(Var); /* Allign the last Decimal point as the 4th position from the end of string */ /* use the Ods char \~ as a digit space - note a 'space' is not as wide as a digit */ %Macro FixDecPos; CurDecPos=Index(Left(Reverse(Val)),'.'); If CurDecPos ne 4 Then Do; NumSpa = 4-CurDecPos; Spa=Repeat('\~',NumSpa+1); Val=Compress(Trim(Left(Val))!!"\R/RTF"!!"'"!!Compress(Spa)!!"'"); End; %Mend FixDecPos; Typ="&Var.";Cat="Ave"; Val= &Var.Ave ;%FixDecPos; OutPut; Typ="&Var.";Cat="Std"; Val= &Var.Std ;%FixDecPos; OutPut; Typ="&Var.";Cat="Xmn"; Val= &Var.Xmn ;%FixDecPos; OutPut; %Mend TypVal; %TypVal(Age); %TypVal(Hgt); %TypVal(Wgt); %TypVal(Dia); %TypVal(Sys); %Macro TypValFrqPct(Var); Typ="&Var.";Cat="Pct"; Val= &Var.Pct ;%FixDecPos; OutPut ; %Mend TypValFrqPct; %TypValFrqPct(Mal); %TypValFrqPct(Fem); %TypValFrqPct(Bla); %TypValFrqPct(Whi); %TypValFrqPct(USA); %TypValFrqPct(Eur); %TypValFrqPct(Ins); %TypValFrqPct(Uni); run; Proc Sort Data=MkeRow Out=MkeRowSrt; By Typ Cat Trt; Run; Proc Transpose Data=MkeRowSrt Out=MkeXpo(Drop=_Name_); By Typ Cat; Var Val; Id Trt; Run; Proc Format; Value $Typ2Des 'Age'='Age(yrs)' 'Wgt'='Weight(kg)' 'Hgt'='Height(m)' 'Fem'='Female' 'Mal'='Male' 'USA'='United States' 'Eur'='European' 'Dia'='Diastolic Pressure(mmhg)' 'Sys'='Systolic Pressure(mmhg)' 'Bla'='African American' 'Whi'='Caucasian' 'Ins'='Uninsured' 'Uni'='Insured' ; Value $Typ2Ord 'Age'='01' 'Wgt'='02' 'Hgt'='03' 'Dia'='04' 'Sys'='05' 'Fem'='06' 'Mal'='07' 'USA'='08' 'Eur'='09' 'Bla'='10' 'Whi'='11' 'Ins'='12' 'Uni'='13' ; Value $Cat2Des 'Ave'="\S={font_weight=bold font_size=11pt}Mean" 'Std'="\S={font_weight=bold font_size=11pt}Std" 'Xmn'="\S={font_weight=bold font_size=11pt}(Max,Min)" 'Pct'="\S={font_weight=bold font_size=11pt}(n,%)" ; run; options orientation=portrait;run; Proc Sql; Create Table MkeFin as Select *, Case When Typ In ('USA' 'Eur' 'Bla' 'Whi' 'Uni' 'Ins' ) Then 2 Else 1 End as Pge From MkeXpo Order by Put(Typ,$Typ2Ord.), Cat; quit; run; Proc sql; select max(pge) into :MaxPge from MkeFin;quit; Ods rtf file="d:\rtf\demtbl.rtf" style=LineUp; Ods EscapeChar='\'; Title; Footnote;run; Proc Report Nowd Data=MkeFin ; Cols Pge Typ Cat Placebo Potion7 Potion8 Potion9 ; %let hdr= %str(\S={font_weight=bold font_size=11pt cellwidth=1in}); define pge / Order noprint; define typ / Order "&Hdr.Parameter" Style={Just=r} Noprint Order=Data; define Cat / display "&Hdr.Parameter" Style={Just=r} Format=$Cat2Des.; define Placebo / display "&Hdr.&Placebo." Style={Just=r}; define Potion7 / display "&Hdr.&Potion7." Style={Just=r}; define Potion8 / display "&Hdr.&Potion8." Style={Just=r}; define Potion9 / display "&Hdr.&Potion9." Style={Just=r}; Break before Pge / Suppress Page; Compute Before _page_; MaxPge=&MaxPge.; PgeNofM="&Hdr.Page "!!put(Pge,1.)!!" of "!!put(MaxPge,1.); Line @1 PgeNofM $64.; EndComp; Compute Before Typ; Length Txt $64; Dum='09'x; Line @1 Dum $1.; Txt="&Hdr."!!Put(Typ,$Typ2Des.); Line @1 Txt $64.; EndComp; run; quit; run; ods rtf close; run;