-
Notifications
You must be signed in to change notification settings - Fork 0
/
使用迴圈產生macro_variable.sas
160 lines (128 loc) · 3.59 KB
/
使用迴圈產生macro_variable.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
libname NH 'C:\Users\Hong Guo-Peng\Desktop\SAS_demo\SAS_healthy_insurance_demo\SAS_dataset'; run;
/*macro variable 格式 怎麼看? ->基本上都文字 */
data _null_;
call symput('today', year(today()));
run;
%put &today. ;
%let condition5 = %str(&today. - birth_yy >= 65);
/*way 1 */
data NH.test;
length condition_ $ 6000;
retain condition_ ;
do i =1 to 4 ;
if i = 1 then do;
condition_ = catx(' or ' , condition_ ,
"substr(ICD9CM_CODE , 1 , 3) in ('410' '411' ' 412' '413' '414')");
end;
else if i ^= 1 then do;
a = "substr(ICD9CM_CODE_" ;
b = put(i-1 , $1.) ;
c = ", 1 , 3) in ('410' '411' ' 412' '413' '414')" ;
condition_ = catx(' or ' , condition_ , cat( a , b , c ));
end;
output;
end;
call symput('condition' , condition_);
proc print;
run;
%put &condition.;
%macro makesets;
proc sql;
create table NH.Dd2008_disease as
select FEE_YM , APPL_TYPE , HOSP_ID , APPL_DATE , CASE_TYPE , CASE_TYPE , ID , ID_BIRTHDAY , IN_DATE , ICD9CM_CODE , ICD9CM_CODE_1 , ICD9CM_CODE_2 , ICD9CM_CODE_3 , ID_SEX ,
INPUT(substr(ID_BIRTHDAY , 1 , 4) , 4.) as birth_yy , INPUT(substr(ID_BIRTHDAY , 5 , 2) , 2.) as birth_mm
from NH.Dd2008
;
quit;
proc sql;
create table NH.Dd2008_disease as
select * , &today. - birth_yy as age
from NH.Dd2008_disease
;
quit;
proc sql;
create table NH.test as
select *
from NH.Dd2008_disease
where &condition. and &condition5.
;
quit;
/*把目標患者ID找出來*/
proc sql;
create table NH.test_ as
select distinct(ID) as ID
from NH.test
;
quit;
%mend makesets;
%makesets;
libname NH 'C:\Users\Hong Guo-Peng\Desktop\SAS_demo\SAS_healthy_insurance_demo\SAS_dataset'; run;
/*macro variable 格式 怎麼看? ->基本上都文字 */
data _null_;
call symput('today', year(today()));
run;
%put &today. ;
%let condition5 = %str(&today. - birth_yy >= 65);
/*way 2 */
%macro makesets;
%do i=1 %to 1;
%do j=1 %to 4;
%let i_j = %eval(4*(&i. - 1) + &j.);
%let string = ('410' '411' ' 412' '413' '414');
%if &j. = 1 %then %do;
%let condition&i_j. = substr(ICD9CM_CODE , 1 , 3) in &string.;
%end;
%else %if &j. ^= 1 %then %do;
%let jj = %eval(&j. - 1);
%let condition&i_j. = substr(ICD9CM_CODE_&jj. , 1 , 3) in &string.;
%end;
%put &&condition&i_j.;
%end;
%end;
/*For 2008 患有缺血性心臟病的病患找出來*/
proc sql;
create table NH.Dd2008_disease as
select FEE_YM , APPL_TYPE , HOSP_ID , APPL_DATE , CASE_TYPE , CASE_TYPE , ID , ID_BIRTHDAY , IN_DATE , ICD9CM_CODE , ICD9CM_CODE_1 , ICD9CM_CODE_2 , ICD9CM_CODE_3 , ID_SEX ,
INPUT(substr(ID_BIRTHDAY , 1 , 4) , 4.) as birth_yy , INPUT(substr(ID_BIRTHDAY , 5 , 2) , 2.) as birth_mm
from NH.Dd2008
;
quit;
proc sql;
create table NH.Dd2008_disease as
select * , &today. - birth_yy as age
from NH.Dd2008_disease
;
quit;
%do i=1 %to 4;
%if &i. = 1 %then %do;
data NH.test;
set NH.Dd2008_disease ;
if &&condition&i. then condition_&i. = 1;
else condition_&i. = 0;
condition = condition_&i.;
run;
%end;
%else %if &i. ^= 1 %then %do;
%let ii = %eval(&i. - 1);
data NH.test;
set NH.test (drop = condition_&ii.);
if &&condition&i. then condition_&i. = 1;
else condition_&i. = 0;
condition = condition + condition_&i. ;
run;
%end;
%end;
data NH.test (drop = condition_4);
set NH.test ;
if &condition5. or condition> 0 then output;
run;
/*把目標患者ID找出來*/
proc sql;
create table NH.test_ as
select distinct(ID) as ID
from NH.test
;
quit;
%mend makesets;
%makesets;
;*';*";*/quit;run;