|
It might surprise you that I got the original code from the SAS online
documentation v8 some years back. I wasn't trying to modify or anything
until I ran into the problem I mentioned earlier.
This can be found in the page titled "%STR and %NRSTR" at
http://v8doc.sas.com/sashtml/.
This is the code snippet that I took from the SAS Online Doc and that is
what SAS Insitute is using to tell others! :-)
--Curtis E. Reid
Example 2: Protecting a Blank So That It Will Be Compiled As Text
This example specifies that %QSCAN use a blank as the delimiter between
words.
%macro words(string);
%local count word;
%let count=1;
%let word=%qscan(&string,&count,%str( ));
%do %while(&word ne);
%let count=%eval(&count+1);
%let word=%qscan(&string,&count,%str( ));
%end;
%let count=%eval(&count-1);
%put The string contains &count words.;
%mend words;
%words(This is a very long string)
Executing this program writes these lines to the SAS log:
The string contains 6 words.
|