Dear Sas Community, I'm having troubles understanding why this code, with %str(;) inside of a sysfunc call in a loop is not working: %macro split_terms;
%let terms = %str(This is a term; This is another term, with a comma; And this is a third term);
%do i = 1 %to %sysfunc(countw(&terms, %str(;)));
%put %scan(&terms, &i, %str(;));
%end;
%mend;
%split_terms; But when in sysfunc, I put quotes around semicolon and remove %str like below, it works correctly: %macro split_terms;
%let terms = %str(This is a term; This is another term, with a comma; And this is a third term);
%do i = 1 %to %sysfunc(countw(&terms, ';'));
%put %scan(&terms, &i, %str(;));
%end;
%mend;
%split_terms; The other way around it is to put the resolution of %sysfunc(countw(&terms, %str(;))) into macro variable like: %macro split_terms;
%let terms = %str(This is a term; This is another term, with a comma; And this is a third term);
%let nterms = %sysfunc(countw(&terms, %str(;)));
%do i = 1 %to &nterms.;
%put %scan(&terms, &i, %str(;));
%end;
%mend;
%split_terms; In other statements, like %if, there seems to be no difference in behavior: %let terms = %str(This is a term; This is another term, with a comma; And this is a third term);
%if %sysfunc(countw(&terms, %str(;))) eq %sysfunc(countw(&terms, ';')) %then %do;
%put ---> EQUAL <---;
%END; 24 %put ---> EQUAL <---; ---> EQUAL <--- 25 %END; Is there a difference of behavior when such %sysfunc(countw... statement is used in a loop?
... View more