為什麼這篇SAS 虛擬變數鄉民發文收入到精華區:因為在SAS 虛擬變數這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者aswind0614 (青雨萌)看板Statistics標題[問題] SAS跑迴歸之虛擬變項一直...
我用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)