谁能告诉我为什么这不能解决:
/*put all transaction table names into a data set*/
/*(table names are of format transac_20130603_20130610 (date from and date to)*/
data transaction_tables;
set SASHELP.VTABLE (keep=libname memname);
where lowcase(substr(memname,1,8))='transac_'
run;
/*sort and add rownumbers*/
proc sql;
create table transaction_tables as
select *, monotonic() as rownum
from transaction_tables
order by memname;
run;
/*find rownumber of first and last transaction tables with run dates before campaign start and after end date of campaign*/
data _NULL_;
set transaction_tables;
if substr(memname,9,8)<=&pre_period_start. and substr(memname,18,8)>=&pre_period_start. then do;
call symput("r1", rownum);
stop;
end;
run;
data _NULL_;
set transaction_tables;
if substr(memname,9,8)<=&max_enddate. and substr(memname,18,8)>=&max_enddate. then do;
call symput("r2", rownum);
stop;
end;
run;
%put &r1; %put &r2;
/*r1 = 11, r2 = 27 - both resolving OK*/
/*get all relevant transaction table names where rownumbers are between r1 and r2*/
/*r1=11 and r2=27 so my transaction table name macros should run from t_0 to t_16/*
%macro trans;
%let y = %eval(&r2 - &r1);
%do i=0 %to &y;
data _NULL_;
set transaction_tables;
if rownum = &r2 - (&r2 - &r1 - &i) then do;
call symput("t_&i", cats(libname, '.', memname));
stop;
end;
%end;
%mend trans;
%trans;
%put &t_0;
--WARNING: Macro variable "&t_0" was not resolved
我不完全确定为什么,但是由于弄乱了一些变量,我认为问题在于它试图将表名分配给 t_&i 宏的最后一部分。我认为问题在于在尝试调用另一个宏变量时尝试命名宏变量(尝试在 i=0 时通过调用 &i 创建宏 t_0)。我想我把语法搞砸了,因为我认为逻辑相当合理。
谢谢!