我希望外循环迭代日期。 内循环遍历不同的位置,然后作为位置的循环结束,然后循环日期循环。位置的内循环工作正常。
我想说明where语句的行
"其中t1.Date BETWEEN' date'和' date1' "我该如何创建该宏?日期和日期1必须同时迭代,以便始终相隔两天。
PROC SQL;
CREATE TABLE WORK.Report_dates&i AS /* every time the date changes/newtable*/
SELECT t1.ReportsID,
t1.Type,
t1.buys,
t1.sells,
t1.Age
FROM work.candy as t1
where (t1.Date BETWEEN '14Feb2016:0:0:0'dt AND '16Feb2016:0:0:0'dt) AND
(t1.Location = "SouthFlorida");
QUIT;
data list_of_dates;
format date date9.;
do Date = '01JUL2016'd to today();
output;
end;
run;
data list_of_dates1;
format date date9.;
do Date1 = '02JUL2016'd to today();
output;
end;
run;
两个循环在测试时单独工作。但是当我把它放在一起的时候,我会继续按照"当前正在处理的引用字符串已超过262个字符。您可能有不平衡的引号。但是我没有任何不平衡的引号,就像我说它们在测试时分开工作但不在一起。
%macro queryLoop(startDate=, i=);
%macro loop(listA, listB);
%let p = %sysfunc(countw(&FACLNBR, %str( )));
%do i=1 %to &p;
%let lista = %scan(&olista, &i, %str( ));
%let listb = %scan(&olistb, &i, %str( ));
PROC SQL;
CREATE TABLE WORK.Report_dates&i AS /* every time the date changes/newtable*/
SELECT t1.ReportsID,
t1.Type,
t1.buys,
t1.sells,
t1.Age
FROM work.candy as t1
where (datepart(t1.Date) BETWEEN &startDate AND &startDate+2 ) AND
(t1.Location = &list);
QUIT;
%end;
%mend;
%loop(listA_1 listA_2, listB_1 listB_2);
%mend queryLoop;
data list_of_dates;
i=1;
format date date9.;
do Date = '01NOV2015'd to '01JAN2016'd;
string = catt('%queryLoop(startDate=', date, ', i=', i, ');');
call execute(string);
i+1;
output;
end;
run;
;*';*";*/;quit;run;
答案 0 :(得分:1)
我认为这是您正在寻找的,基于您之前的问题,这个问题和有根据的猜测。您需要先在宏中包装查询,然后在创建日期时,可以直接使用Call Execute将调用宏传递给那些日期。
请参阅下面的代码。请注意,我已经开始执行调用,因为我无法运行代码。
%macro queryLoop(startDate=, i=);
PROC SQL;
CREATE TABLE WORK.Report_dates&i AS /* every time the date changes/newtable*/
SELECT t1.ReportsID,
t1.Type,
t1.buys,
t1.sells,
t1.Age
FROM work.candy as t1
where (datepart(t1.Date) BETWEEN &startDate AND &startDate+2 ) AND
(t1.Location = "SouthFlorida");
QUIT;
%mend queryLoop;
data list_of_dates;
i=1;
format date date9.;
do Date = '01JUL2016'd to today();
string = catt('%queryLoop(startDate', date, ', i=', i, ');');
*call execute(string);
I+1;
output;
end;
run;