作者aswind0614 (青雨萌)
看板Statistics
标题[问题] SAS跑回归之虚拟变项一直失败
时间Wed Dec 4 17:09:25 2013
我用SAS跑虚拟变项的回归,程式码如下
DATA M2;
INPUT region x1 x2 y @@;
CARDS;
4 8863164 184230 23677
......
(输入440笔资料後)
;
RUN;
/*分region跑回归*/
PROC SORT data=M2 out=sort_M2;
BY region;
RUN;
Proc reg data=sort_M2;
BY region;
Model y=x1 x2;
RUN;
/*产生dummy变项,region从4个变成3个*/
DATA M2_dummy;
set work.M2;
if region=1 then D1=1 else D1=0;
if region=2 then D2=1 else D2=0;
if region=3 then D3=1 else D3=0;
RUN;
proc freq data=M2_dummy;
tables region*D1*D2*D3/List;
Run;
结果只有跑出分region的结果,dummy失败。
SAS出现结果:
1 DATA M2;
2 INPUT region x1 x2 y @@;
3 CARDS;
NOTE: 当 INPUT 陈述式延伸超过行尾时,SAS 跳到了新的一行。
NOTE: The data set WORK.M2 has 440 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
444 ;
445 RUN;
446
447
448 PROC SORT data=M2 out=sort_M2;
449 BY region;
450 RUN;
NOTE: There were 440 observations read from the data set WORK.M2.
NOTE: The data set WORK.SORT_M2 has 440 observations and 4 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
451 Proc reg data=sort_M2;
NOTE: 正在写入 HTML Body (本文) 档案: sashtml.htm
452 BY region;
453 Model y=x1 x2;
454 RUN;
NOTE: 已透过 BY 处理停用互动性。
NOTE: PROCEDURE REG used (Total process time):
real time 2.99 seconds
cpu time 1.03 seconds
455
456 DATA M2_dummy;
457 set work.M2;
458 if region=1 then D1=1 else D1=0;
----
388
202
459 if region=2 then D2=1 else D2=0;
----
388
202
460 if region=3 then D3=1 else D3=0;
----
388
202
ERROR 388-185: Expecting an arithmetic operator.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
461 RUN;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.M2_DUMMY may be incomplete. When this step was
stopped there were
0 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
462 proc freq data=M2_dummy;
463 tables region*D1*D2*D3/List;
464 Run;
NOTE: No observations in data set WORK.M2_DUMMY.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
请问我的dummy为什麽会跑不出来?
还是说我从第二部份就开始写错了呢?
谢谢>///<
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.92.139
※ 编辑: aswind0614 来自: 140.112.92.139 (12/04 17:22)
1F:推 tew:共线性吧 12/04 22:38
2F:推 JKY:458 ~ 460有说明错误 12/04 23:01
3F:推 imaltar: if region=1 then D1=1 後要加分号(;) 再用ELSE 12/04 23:03
4F:→ BugEater:在sas里面不需要做dummy的,用class就可以。 12/05 07:35
5F:→ aswind0614:谢谢楼上各位大大!我跑出来了:) 12/05 22:10