以下Macro可以協助解決這個問題,
**************************Beginning***********************************;
%macro Dz_times(data_in,dz_date_name,occur1,occur2,data_out);
data b1;set &data_in;
by
id;
dz_date2=input(&dz_date_name,yymmdd8.);
one_yr_&occur1.times=ifn(
first.ID , (.) , dif&occur2.(dz_date2)
);
if
30<one_yr_&occur1.times<=365 then day365_&occur1.times=1;
run;
data day365_&occur1.times; set b1;if
day365_&occur1.times=1;run;
data &data_out; set
day365_&occur1.times; by id; if first.id ;run;
*有 ? 人在一年內發生occur1
次疾病;
%mend;
%Dz_times(data_in=DM_op_all,dz_date_name=dz_date,occur1=4,occur2=3,data_out=b2);
*變項解釋;
*data_in:放入的資料之名稱;
*dz_date_name:疾病發生日期的變數之名稱;
*occur1:一年內發生多少次疾病;
*occur2:請填入occur1-1的數字 (可以再想如何改寫語法);
*data_out:輸出的資料之名稱;
******************************End**********************************;
沒有留言:
張貼留言