3

我在 X 上回归 Y。回归按 DATE 分组。

proc reg data=A noprint;
    model Y=X;
    by DATE;
run;

在每个 DATE 的回归结果中,都有一个 R 平方和一个 RMSE 值。如何输出 R 平方和 RMSE 值表,如下所示。谢谢!

|------------|-----------|------------|
|    Date    |  R Square |    RMSE    |
|------------|-----------|------------|
|  1/1/2009  |     R1    |    RMSE1   |
|  2/1/2009  |     R2    |    RMSE2   |
|  3/1/2009  |     R3    |    RMSE3   |
|    ....    |    ....   |    ....    |
|  10/1/2010 |     R22   |    RMSE22  |
|  11/1/2010 |     R23   |    RMSE23  |
|  12/1/2010 |     R24   |    RMSE24  |
|------------|-----------|------------|

4

2 回答 2

5

如果您查看 SAS PROC REG 的示例之一,这很容易做到。

示例数据:

data htwt;
      input sex $ age :3.1 height weight @@;
      datalines;
   f 143 56.3  85.0 f 155 62.3 105.0 f 153 63.3 108.0 f 161 59.0  92.0
   f 191 62.5 112.5 f 171 62.5 112.0 f 185 59.0 104.0 f 142 56.5  69.0
   f 160 62.0  94.5 f 140 53.8  68.5 f 139 61.5 104.0 f 178 61.5 103.5
   f 157 64.5 123.5 f 149 58.3  93.0 f 143 51.3  50.5 f 145 58.8  89.0
   m 164 66.5 112.0 m 189 65.0 114.0 m 164 61.5 140.0 m 167 62.0 107.5
   m 151 59.3  87.0
   ;
run;

现在,PROC REG。特别注意 OUTEST 语句;这将输出一个est1包含你想要的数据集。

proc reg outest=est1 outsscp=sscp1 rsquare;
      by sex;
      eq1: model  weight=height;
      eq2: model  weight=height age;

   proc print data=sscp1;
      title2 'SSCP type data set';

   proc print data=est1;
      title2 'EST type data set';
   run;
quit;

所以现在, est1 的最后一个 PROC PRINT 可以很容易地路由到只包含你想要的内容:

proc print data=est1;
var sex _RMSE_ _RSQ_;
run;
于 2013-07-03T13:46:59.567 回答
3

You can use this code:

proc reg data=A noprint;
model Y=X;
by DATE;
ods output FitStatistics=final_table;
run;
data final_table; set final_table;
    rename cValue1=RMSE;
    rename cValue2=RSquared;
proc print data=final_table;
    where Label1='Root MSE';
    var DATE RSquared RMSE;
run;

I simply turned the trace on and took the name of the table I was interested in and saved it as the output of proc reg.

ODS Trace on;
proc reg data=A noprint;
model Y=X;
by DATE;
run;
ODS Trace off;

this prints out the name of all the output tables in the log file.

于 2013-07-03T14:11:37.287 回答