What's wrong with these macro parameters?

76 views Asked by At

I have the following simplified version of a piece of code that I am working on:

%macro test(var);

%if &var = 'Sub Prime' %then %do;
%let var2 = 'Sub_Prime';
%put &var2;
%end;
%mend;

%test(Sub%str( )Prime);

Basically the point of this is that if var = 'Sub Prime' that var2 should = 'Sub_Prime'. It appears though that var does not equal 'Sub Prime'. Can anyone tell me what I am doing wrong?

Thanks

1

There are 1 answers

4
Joe On BEST ANSWER

Macro variables do not use quotations.

%macro test(var);

%if &var = %str(Sub Prime) %then %do;
  %let var2 = Sub_Prime;
  %put &=var2;
%end;
%mend;

%test(Sub%str( )Prime);

You'd be better off using %str around the whole thing, though, rather than inserting the %str in just the space.

%test(%str(Sub Prime));