楼主: 夭妖
5759 14

【请教】SAS回归模型保存 [推广有奖]

11
pandasasa 发表于 2010-5-20 15:49:37
不知你是想要用数据集a的回归结果还是仅仅想提取自变量名,如果是前者可以考虑前面soporaeternus 提到的:
data a(drop=i);
do i=1 to 100;
x1=ranuni(i);
x2=2*uniform(i);
y=2*x1+3*x2;
output;
end;
run;
data b(drop=i);
do i=1 to 50;
x1=ranuni(i);
x2=2*uniform(i);
y=2*x1+3*x2;
output;
end;
run;
proc sql noprint;
create table varname
as select name
from dictionary.columns
where libname="%upcase(work)"
      and type='num' and memname="%upcase(a)"
       and name ne "y";
select name into :var separated by ' '
from varname;
quit;
proc reg data=a outest=n ;
new_y: model y=&var/selection=stepwise;
run;
quit;
proc score  data=b score=n out=c
              type=parms predict;
var &var;
run;
quit;

12
cz851218 发表于 2010-5-20 20:58:13
6# pobel
能够解释下吗,看有点困难!!

13
夭妖 发表于 2010-5-20 21:08:54
谢谢各位啦~~最终用了proc score~~
Marco还没学~看不太懂~努力中~

14
crackman 发表于 2010-5-20 21:46:28
熟悉的面孔
熟悉的技巧

15
bobguy 发表于 2010-5-21 08:17:52
夭妖 发表于 2010-5-20 11:15
问题是这样的:我在A数据集中得到了回归模型,
怎么样把这个回归模型运用到其他数据集B上呢?
两个数据集的 列名设置为一样的,
但是,由于自变量比较多,不能手工输入,
所以请教一下大家~非常谢谢~
There are a couple of ways can think of.
1) set both dataset togather ....  
2) use proc score ...
See example below.



data a(keep=y x:) b(keep=x:);
   do i = 1 to 40;
      x1=rannor(123); x2=rannor(123); x3=rannor(123); err= rannor(123);
      y=1+1*x1+0.5*x2+0.3*x3+err;
      if i <=30 then output a ;
      else output b;
    end;
run;

***    use proc reg while doing a regression;
data ab;
   set a b;
run;

proc reg data=ab;
   model y= x1 x2 x3;
   output out=pred p=py;
run;
quit;

proc print data=pred; run;


****use proc score****;
proc reg data=a outest=parms;
   model y= x1 x2 x3;
run;
quit;

proc score  data=b score=parms out=bp predict type=parms;
var x1 x2 x3;
run;

proc print data=bp;
run;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 02:16