/******************************************************************** * NAME: qlist SYSTEM: MSCDC PGMR: BLODGETT * * FUNCTION: parses parm with string of words and returns a * * string with each word in quotes, separated by commas. * ********************************************************************/ /*--this utility macro function takes a global parm reference as its sole argument. That parm should contain a list of words. The function returns a list of those words contained in double quotes and separated by commas. E.g. if str= a b c then result returned is "a","b","c". j. blodgett, 4-96----- --sample invocation of qlist-- ****************************** %let s=29001 29003 17163 xyz; data _null_; retain s "&s"; retain qs "%qlist(&s)"; put _all_; stop; run; (The value of qs becomes "29001","29003","17163","xyz") ---- */ /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %macro qlist(str,check=1); %local dq word i qstr comma blank; %let qstr=; %let comma=; %let blank=%str( ); %if &check %then %do; %*--check=0 will cause this test to be skipped--; %if %quote(&str)=%str() or %quote(&str)=&blank %then %goto _return; %*--_return null value if arg is null or blank; %end; %let dq=%bquote(%str(%")); %*--store quoted double quote-; %let word=%scan(&str,1); %*--get first word-; %let i=1; %do %while (&word ne ); %*--until no more words in str; %let qstr=&qstr&comma&dq&word&dq; %let i=%eval(&i+1); %let word=%scan(&str,&i); %let comma=%str(,); %end; %_return: %unquote(&qstr) %*--_returns whatever is in qstr macro var; %mend qlist;