data test;
input age aaa y;
datalines;
1 1 1
2 2 2
3 3 3
1 4 3
2 5 3
5 5 3
4 5 3
3 1 3
;
run;
%dummy(mydata = test, outdumydata = test2, classvar = age aaa, nclassvar = age, mergedata = test34)
%macro dummy(mydata, outdumydata, classvar, nclassvar, mergedata);
/*================================================================================*/
/*%let mydata = test;*/
/*%let outdumydata = test2;*/
/*%let classvar = age aaa;*/
/*%let nclassvar = age;*/
/*%let mergedata = test3;*/
/*================================================================================*/
proc logistic data = &mydata outdesign = &outdumydata outdesignonly;
class &classvar / param = glm;
model &nclassvar = &classvar / noint;
run;
quit;
/*proc print data = &outdumydata noobs;*/
/*run;*/
data &mergedata;
merge &mydata &outdumydata;
run;
%mend;
|
原始資料 要將 age 與 aaa 生成虛擬變數 |
|
test2 虛擬變數 |
|
原始資料與虛擬變數合併 merge沒有使用by 表示 test第n筆與test2第n筆合併 |
%dummy(mydata = 原始資料集, outdumydata = 輸出虛擬變數資料集, classvar = 要生成虛擬變數的變數(可多個), nclassvar = 第一個要生成虛擬變數的變數, mergedata = 輸出資料集)