BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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

1 REPLY 1
hashman
Ammonite | Level 13

@knveraraju91:

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. 

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1420 views
  • 1 like
  • 2 in conversation