Reputation: 73
I am testing the macro loop. The code is simple but always come the error message "Macro function %SCAN has too many arguments". Could not understand the reason. Anyone could explain it? Thanks! The code is:
%macro test;
proc sql;select distinct tj, max(tj) into: tp separated by ",", : maxtp from ASA_k where tj>0;quit;
%do i=1 %to &maxtp.;
%let timep=%scan(&tp.,&i.,",");
%put &timep.;
%end;
%mend;
%test;
Upvotes: 1
Views: 4181
Reputation: 1188
In macro-varriable, you store values separated by commas, these commas are problematic. You need to mask them after resolving a macro-variable, using %bquote
macro-function. Also your third parameter in %scan
function is not right, because your separator are ,
and "
. You have to just mask comma using %str
macro-function. Just like that:
%macro test;
proc sql;
select distinct tj, max(tj)
into :tp separated by ",", :maxtp
from ASA_k
where tj>0;
quit;
%do i=1 %to &maxtp.;
%let timep=%scan(%bquote(&tp.),&i.,%str(,));
%put &timep.;
%end;
%mend;
%test;
Upvotes: 8