Dear,
Please suggest why the macro 'want' is not executing. I need to output data set 'two'. Thank you
data one;
input a $10.;
datalines;
aaaa+bbbbb
cccc+ddddd
;
%global treat1 treat2;
proc sql noprint;
select strip(put(count (distinct a), best.)) into: cnt from one;
select distinct a into :treat1 -:treat&cnt. from one
order by a;
quit;
%put &treat1.;
%macro want;
%if %index(&treat1.,'+')>0 %then %do;
data two;
set one;
run;
%end;
%mend;
%want;
data set
Get rid of the single quotes around the +, i.e. instead of '+', code:
%if %index (&treat1, +) > 0 %then %do ;
The macro language is character-based and understands tokens literally - i.e., if you code '+', that is what the %index function will be looking for, replete with the quotes; and there're no quotes in your &treat1 value. And, while at that, get rid of the superfluous period after &treat1 - as Ian Whitlock repeatedly stated, it's a bad habit to code a period after a dereferenced macro variable "just in case" without the exact reason why it must be used - i.e. to avoid macro resolution ambiguity or include a period in the macro-generated text. It leads to nothing but confusion.
Kind regards
Paul D.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.