model_proc_report.txt /* create simulated data with which to create a report */ data DemoData (drop = i); length gender region exposure 8; do i = 1 to 2000; exposure = ranbin(12345,1,0.20); select; when(exposure = 1) do; gender = ranbin(12345,1,0.53); region = rantbl(12345,0.52,0.22,0.12,0.09,0.05); end; when(exposure = 0) do; gender = ranbin(12345,1,0.5); region = rantbl(12345,0.55,0.25,0.10,0.06,0.04); end; otherwise; end; output; end; run; /* create user-defined formats for this report */ proc format; value gender /* format for infant gender variable */ 1 = 'Male' 0 = 'Female'; value region /* format for region of birth variable */ 1 = 'Mid-Lands' 2 = 'High-Lands' 3 = 'Low-Lands' 4 = 'Other-lands' 5 = 'Unknown'; value $variable /* format for variable names */ 'gender' = 'Gender of infant' 'region' = 'Region of birth'; run; ***Calculate counts***; proc means data = DemoData noprint n sum mean; class gender region; var exposure; ways 1; output out = PreTable n = sum = mean = / autoname; run; ***Acting on the dataset generated by PROC MEANS, create the column information required for the report***; data table (keep = variable levels exposure_N exposure_sum exposure_mean pct ExpPct indexvar); set PreTable; length variable $ 20; *** These four variables ***; length levels $ 20; *** will describe the first ***; length pct $ 8; *** four columns of the table ***; length ExpPct $ 15; if gender ne . then do; ***Building "variable" and "Levels" columns for "Gender" ***; variable = 'gender'; levels = put(gender,gender.); IndexVar = 1; ***This index is included just in case the order of data presentation needs to be changed ***; end; if region ne . then do; ***Building "variable" and "Levels" columns for "region" ***; variable = 'region'; levels = put(region,region.); IndexVar = 2; end; pct = put(exposure_mean*100,4.1); ***Calculate % exposed ***; ExpPct = compress(put(exposure_sum,comma4.),' ') ||' '||'('||compress(pct,' ')||')'; ***creating data in the form of "count (%)" ***; run; /* Generating chi-square results for exposure crossed with characteristics */ ods trace on; ods output chisq = ChiData; proc freq data = DemoData; table exposure*gender / chisq; table exposure*region / chisq; run; ods trace off; /* creating a variable so that chi-square results may be merged with our frequency data */ data ChiData2 (keep = variable prob); set ChiData (where = (statistic = 'Chi-Square')); length variable $ 20; variable = scan(table,-1,' '); /* Returns the last word in a character value from the "table" variable */ run; proc sort data = table; by variable; run; /* Creating final data set, we are ready to use PROC REPORT */ data TableData; merge table (in = a) ChiData2 (in = b); by variable; if a; run; proc sort data = TableData;***this step is only necessary if the index variable is changed***; by IndexVar; run; ods escapechar = '~'; option nodate nonumber orientation = landscape; ods rtf file = "OutPutPath" bodytitle; Proc report data = TableData nowd style(report) = {cellpadding = 1.25pt cellspacing = 0pt frame = hsides rules = groups} style(header) = {font = ("arial",11pt) background = white} style(column) = {font = ("arial",11pt)}; column variable levels exposure_N ExpPct prob; define variable / "Variable" group format = $variable. style(header) = {just = left} style(column) = {cellwidth = 1.5in}; define levels / " " Style(column) = {cellwidth = 1.5in}; define exposure_N / "All births/n/(n = 2,000)" format = comma5. style(column) = {just = right cellwidth = 1.25in rightmargin = .4in}; define ExpPct / "Number exposed/n (%)/(n = 420)" style(column) = {cellwidth = 1.25in just = right rightmargin = .25in} ; define prob / "p-value~{super 1}" group style(column) = {just = center}; compute before variable; line ' '; endcomp; /* Inline formatting and title/footnote text on the same statement line may be written in separate quote groups */ Title '~S={leftmargin = 2.25in font = ("arial",11pt) just = left}' 'Table 1: Characteristics of Subjects'; footnote '~S={leftmargin = 2.25in font = ("arial",9pt) just = left}~{super 1}' 'Chi-square test for association'; run; ods rtf close; title; footnote;