Hi Team,
Kindly help me to apply %if,%then and %else condition on following case.
Step 1 : Creating macro variables for dates
data _null_; END_DT = intnx('month',today(),0,'e'); END_DT_2LST = intnx('month',today(),-1,'e'); END_DT_CURR = intnx('month',today(),1,'e'); call symput('END_DT', "'"||put(END_DT,date9.)||"'d"); call symput('END_DT_2LST', "'"||put(END_DT_2LST,date9.)||"'d"); call symput('END_DT_CURR', "'"||put(END_DT_CURR,date9.)||"'d"); run;
data test; CURR_ED = intnx('month',&END_DT.,-1,'e'); CURR_SD1 = intnx('month',&END_DT.,-1,'b'); LST_ED = intnx('month',&END_DT.,-2,'e'); LST_SD24 = intnx('month',&END_DT.,-25,'b'); call symput('CURR_ED', "'"||put(CURR_ED,date9.)||"'d"); call symput('CURR_SD1', "'"||put(CURR_SD1,date9.)||"'d"); call symput('LST_ED', "'"||put(LST_ED,date9.)||"'d"); call symput('LST_SD24', "'"||put(LST_SD24,date9.)||"'d"); run;
data _null_; call symput ("SCR_MNTH", compress(put((intnx('MONTH',&CURR_ED.,1,'e')),monyy5.))); call symput ("LST_MNTH",compress(put((intnx('MONTH',&CURR_ED.,0,'e')),monyy5.))); call symput ("LST2_MNTH",compress(put((intnx('MONTH',&CURR_ED.,-1,'e')),monyy5.))); run;
%macro data_prep(END_DT=);
Proc sql;
create table Tran_&LST_MNTH._DV as
Select cust_id, flg_del from source
where DATE between &LST_SD24. and &LST_ED.; quit;
%if "&END_DT."="&END_DT." %then %do;
Data Tran_&LST_MNTH._DV;
set Tran_&LST_MNTH._DV;
run;
%end;
%if "&END_DT."="&END_DT_2LST." %then %do;
Data Tran_&LST2_MNTH._DV;
set Tran_&LST_MNTH._DV;
where flg_del=1;
run;
%end;
%if "&END_DT."="&END_DT_CURR." %then %do;
Data Tran_&SCR_MNTH._DV;
set Tran_&LST_MNTH._DV;
where flg_del=0;
run;
%end;
%mend data_prep;
%data_prep(END_DT=&END_DT.);;
%data_prep(END_DT=&END_DT_2LST.);
%data_prep(END_DT=&END_DT_CURR.);
i have just given you the approach, i am trying with it.
It's a huge repetitive code, running for consecutive three months. Only one step is different. Due to only that, code has been written three times. Kindly help me so that i can reduce the length of code.
... View more