SAS Macro Do Loop not resolving -
can tell me why isn't resolving:
/*put transaction table names data set*/ /*(table names of format transac_20130603_20130610 (date , date to)*/ data transaction_tables; set sashelp.vtable (keep=libname memname); lowcase(substr(memname,1,8))='transac_' run; /*sort , add rownumbers*/ proc sql; create table transaction_tables select *, monotonic() rownum transaction_tables order memname; run; /*find rownumber of first , last transaction tables run dates before campaign start , after end date of campaign*/ data _null_; set transaction_tables; if substr(memname,9,8)<=&pre_period_start. , substr(memname,18,8)>=&pre_period_start. do; call symput("r1", rownum); stop; end; run; data _null_; set transaction_tables; if substr(memname,9,8)<=&max_enddate. , substr(memname,18,8)>=&max_enddate. do; call symput("r2", rownum); stop; end; run; %put &r1; %put &r2; /*r1 = 11, r2 = 27 - both resolving ok*/ /*get relevant transaction table names rownumbers between r1 , r2*/ /*r1=11 , r2=27 transaction table name macros should run t_0 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) do; call symput("t_&i", cats(libname, '.', memname)); stop; end; %end; %mend trans; %trans; %put &t_0; --warning: macro variable "&t_0" not resolved i'm not entirely sure why messing around few of variables think problem lies last part attempting assign table names t_&i macros. think issue trying name macro variable while trying call macro variable (trying create macro t_0 calling &i when i=0). guess i've screwed syntax because think logic sound.
thanks!
without judging usefulness of you're trying do:
it scope issue. macro variable create within macro, exists within macro. if want exist outside macro, either need to:
- create macro variable in open code (not in macro) , before execute macro.
set explicitly global within macro (before first mention of it), writing:
%global t_0;
edit note end proc sql, need use quit instead of run.
Comments
Post a Comment