The following code creates a table of results for a series of regressions. The resulting table will look like the one shown below. The coefficients for each variable are listed, with their standard errors listed below them in parentheses.
As a first step, we need to define a format for the standard errors. Specifically, we need to tell SAS we want to set the number of decimal places displayed and put the value of the standard error in a set of parentheses ( "(" and ")" ). The picture statement tells SAS we want to create a format for printing numbers. The ‘ 9.99)’ tells SAS that we would like a number with up to two decimal places, and that the number should be followed by a ")". The (prefix='(‘) requests that the printed value be prefixed with "(". The final line instructs SAS that missing values should be shown as blank spaces.
proc format; picture stderrf (round) low-high=' 9.99)' (prefix='(') .=' '; run;
Next we use the output delivery system (ODS) to capture the results from a series of regression models. The persist option allows ODS to collect output from more than one model statement; otherwise, the output would be collected only for the first model. Below the proc reg run, we stop collecting output with the ods output close statement. Finally, we print the contents of the new dataset containing our regression results.
ods output ParameterEstimates (persist) = t; proc reg data = "d:datahsb2" ; model write = female; model write = female read; model write = female read math; model write = female read math science; model write = female read math science socst; run; ods output close; proc print data=t; run; D e V E p a s _ e r t S t P _ M n i i t V P L r R o d a m d a r a O o u d e b a E l o b b c n e n l D t r u b e s _ _ l t e F e r e t l 1 Reg 1 MODEL1 WRITE Intercept 1 50.12088 0.96281 52.06 <.0001 Intercept 2 Reg 1 MODEL1 WRITE FEMALE 1 4.86995 1.30419 3.73 0.0002 3 Reg 1 MODEL2 WRITE Intercept 1 20.22837 2.71376 7.45 <.0001 Intercept 4 Reg 1 MODEL2 WRITE FEMALE 1 5.48689 1.01426 5.41 <.0001 5 Reg 1 MODEL2 WRITE READ 1 0.56589 0.04938 11.46 <.0001 reading score 6 Reg 1 MODEL3 WRITE Intercept 1 11.89566 2.86285 4.16 <.0001 Intercept 7 Reg 1 MODEL3 WRITE FEMALE 1 5.44337 0.93500 5.82 <.0001 8 Reg 1 MODEL3 WRITE READ 1 0.32524 0.06073 5.36 <.0001 reading score 9 Reg 1 MODEL3 WRITE MATH 1 0.39748 0.06640 5.99 <.0001 math score 10 Reg 1 MODEL4 WRITE Intercept 1 8.58050 2.87450 2.99 0.0032 Intercept 11 Reg 1 MODEL4 WRITE FEMALE 1 5.93672 0.90829 6.54 <.0001 12 Reg 1 MODEL4 WRITE READ 1 0.23276 0.06275 3.71 0.0003 reading score 13 Reg 1 MODEL4 WRITE MATH 1 0.29396 0.06883 4.27 <.0001 math score 14 Reg 1 MODEL4 WRITE SCIENCE 1 0.25702 0.06331 4.06 <.0001 science score 15 Reg 1 MODEL5 WRITE Intercept 1 6.13876 2.80842 2.19 0.0300 Intercept 16 Reg 1 MODEL5 WRITE FEMALE 1 5.49250 0.87542 6.27 <.0001 17 Reg 1 MODEL5 WRITE READ 1 0.12541 0.06496 1.93 0.0550 reading score 18 Reg 1 MODEL5 WRITE MATH 1 0.23807 0.06713 3.55 0.0005 math score 19 Reg 1 MODEL5 WRITE SCIENCE 1 0.24194 0.06070 3.99 <.0001 science score 20 Reg 1 MODEL5 WRITE SOCST 1 0.22926 0.05284 4.34 <.0001 social studies scor
In the table statement, the variable option indicates that the rows should be defined by the values of the variable of that name. That is, there should be one row for each value of variable. The code estimate =' '*sum=' ' requests that the sum of the variable estimate be printed (since there is only one value of estimate for each combination of the variables variable and model, the sum is just the value itself). On the line below we do the same with the variable stderr except that *F=stderrf. applies the format we created above to the values. This takes care of defining what goes in the rows of our table. After the comma (",") we define the columns of our table. The variable name model indicates that there should be one column in the table for each value of the variable model. Throughout the command =' ' is used to set the label for the object it follows to blank.
proc tabulate data=t noseps; class model variable; var estimate stderr; table variable=''*(estimate =' '*sum=' ' stderr=' '*sum=' '*F=stderrf.), model=' ' / box=[label="Parameter"] rts=15 row=float misstext=' '; run;
See also