/*Kazuaki Uekawa's SAS Course*/ /*www.estat.us*/ /*Creating a word document with Table of Contents*/ options noxsync noxwait MPRINT symbolgen mlogic; libname kaz_home "c:/temp/"; /*Sample programming*/ /*data*/ data ABC; set sashelp.class ; ****************; *Creating a character variable indicating a person's BMI status (Body Mass Index); weight_metric=weight*0.45359237; height_metric=(height* 2.54)/100 ; BMI=weight_metric/(height_metric**2); /*Definition of obesity Normal weight = 18.5-24.9 Overweight = 25-29.9 Obesity = BMI of 30 or greater */ length status $ 15; If BMI < 18.5 then status="Underweight"; If BMI => 18.5 and BMI < 25 then status="Normal"; If BMI => 25 and BMI < 30 then status="Overweight"; If BMI >= 30 then status="Obese"; ****************; run; /*1*/ ods listing close; proc means data=ABC mean max min std stderr n lclm uclm alpha=0.05; class age; var height weight BMI ; ods output summary=Mary; run; ods listing; /*2*/ data Mary; set Mary; /*ANNOTATE*/ length magnitude $ 3; if Height_Mean > 40 then magnitude="*"; if Height_Mean > 50 then magnitude="**"; if Height_Mean > 60 then magnitude="***"; run; /*3*/ /*I want to sort observations by average height*/ proc sort data=Mary out=Mary; by Height_Mean; run; /*3. saving as a text file*/ option /*LINESIZE= 110*/ nodate nonumber; ods noproctitle; title; footnote; PROC PRINTTO PRINT="C:\temp\result.txt" new; RUN; options formdlim=' ';/*this suppresses the pagination after this proc*/ %macro kaz (var1=); proc print data=Mary round noobs; title "XXX Descriptive stat for &var1 "; var AGE &var1._Mean magnitude ; run; proc timeplot data=Mary ; title "Time plot for &var1"; plot &var1._LCLM="<" &var1._Mean="*" &var1._UCLM=">"/ overlay ref=mean(&var1._Mean ) hiloc npp pos=40 ; id age Nobs &var1._Mean ; run; %mend kaz; %kaz (var1=Height); %kaz (var1=Weight); %kaz (var1=BMI); PROC PRINTTO PRINT=PRINT; quit; /*Now 1. open the text file with MS-WORD. 2. Replacing XXX with STYLE heading 1: Hit control-H. Type XXX in the first small window. Then hit FORMAT and STYLE. First, just choose (no style) and say Okay. Next, move your cursor to the second window. THen hit FORMAT and STYLE. This time, choose Heading 1. Say Okay. Finally click REPLACE ALL to affect the changes. 3. Go to Insert --> Reference --> Index and Tables --> Choose Table of Contents tab. hit Okay. You will get a table of contents. 4. For cosmetics, adjust the margin and font size. Choose font size 8 using SAS Monospace. If your PC does not have SAS then choose Corrier. */