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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: