Try this: /*Set your starting date ranges*/
%LET STARTDATE = 2012-07-26;
%LET ENDDATE = 2012-07-30;
%LET NUMBER_OF_QUERIES=3;
%MACRO PullData;
%DO I=0 %TO &NUMBER_OF_QUERIES. ;
DATA _NULL_;
/*Determinig the difference between the initial date ranges so subsequent date ranges will do the same*/
DIFFERENCE = (INPUT("&ENDDATE",YYMMDD10.) - INPUT("&STARTDATE",YYMMDD10.))+1;
/*Calculate the date values and create macro variables for the date ranges.*/
CALL SYMPUTX("STARDATE1",PUT(INPUT("&STARTDATE",YYMMDD10.)+SUM(&I.*DIFFERENCE),YYMMDD10.));
CALL SYMPUTX("ENDDATE1",PUT(INPUT("&ENDDATE",YYMMDD10.)+SUM(&I.*DIFFERENCE),YYMMDD10.));
RUN;
Proc SQL;
connect to teradata (database=);
create table here.new&I. as select * from connection to teradata
(
SELECT
d.Nbr,
d.Sequence,
a.Nb,
'-' as Duration,
(Case When a.Dir = b.Dir Then 'S' Else 'M' END) as Type,
AL.Gphc_Adrress,
AL4.Gphc_Adr2,
FROM OP.Base a
LEFT OUTER JOIN MV.STN b ON
(a.Cd=b.Cd AND
a.Cd=b.Cd)
FROM OP.D5a,
MV.D5b
WHERE (Doc=Doc AND
D5.Ldt=LDt AND
D5.Sq=Sq) AND
((D5a.Inav='N' AND
D5a.Ind='N' AND
(D5b.Cd='D' OR D5b.Op='D')
LEFT OUTER JOIN (
SELECT DISTINCT
D.kt,
D.LDt,
D.Sq,
SUM ( D6.Dc )
FROM OPMV.CHRG
WHERE (D6.LDt BETWEEN DATE %BQUOTE(')&STARTDATE1%BQUOTE(') AND DATE %BQUOTE(')&ENDDATE1%BQUOTE('))
GROUP BY
D6.Doc_Nb,
D6.Doc_LDt,
D6.Sq)
AL(nbr, dt, sq, amt) ON
(AL.nbr=AL.nbr
LEFT OUTER JOIN (
SELECT
D7.Doc_Nb,
SUM ( D7b.Dc )
FROM OPMV.TK
LEFT OUTER JOIN OPMV.MISC ON
(D7a.Cur_RM=D7b.Rm_Nb
WHERE ((D7a.LDt BETWEEN DATE %BQUOTE(')&STARTDATE1%BQUOTE(') AND DATE %BQUOTE(')&ENDDATE1%BQUOTE(')
GROUP BY
D7a.Doc_Nb,
D7a.Iss_LDt,
ORDER BY 4,1,3
);
quit;
%END;
%MEND;
%PullData;
... View more