The below macro will generate your SQL code. You can dynamically generate this code for any number of years and quarters. Use the macro calling %UNIONMAC(07,13,3,2) as per your need. %MACRO UNIONMAC(START_YEAR, END_YEAR, START_QTR, END_QTR); %LET X=%SYSFUNC(YYQ(&START_YEAR., &START_QTR.)); %LET Y=%SYSFUNC(YYQ(&END_YEAR., &END_QTR.)); %LET INTERVAL=%SYSFUNC(INTCK(QTR,&X,&Y)); PROC SQL; CREATE TABLE CREDITR.APPEND1_ID AS %DO I=0 %TO &INTERVAL; %LET DATE_INC=%SYSFUNC(INTNX(QTR,&X,&I)); %LET QTR=%SYSFUNC(QTR(&DATE_INC)); %LET YY=%TRIM(%SYSFUNC(YEAR(&DATE_INC))); %IF &I < &INTERVAL %THEN %DO; SELECT * FROM CREDITR.Q&QTR._&YY._CLE2 OUTER UNION CORR %END; %ELSE %DO; SELECT * FROM CREDITR.Q&QTR._&YY._CLE2; QUIT; %END; %END; %MEND UNIONMAC(START_YEAR, END_YEAR, START_QTR, END_QTR); %UNIONMAC(07,13,3,2); Thanks Dhana
... View more