0
votes

I have a macro variable which has more than 1 observation like below.

%let age = 12,34,56;
%put &age;

Now I want to use the age as in my where parameter in proc sql.

proc sql;
select *
from family
where age in ("&age");
quit;

I have used %bquote,%quote,%str() and many more but not successful yet.

1
Why does the title say 'single quote', but you (sort-of-correctly) use double quotes?Joe
True. Might need to change the titleLonelySoul

1 Answers

3
votes

Try without any quotes at all (I assume age is a numeric variable).

And if age is a character one then you can re-write WHERE statement like this;

  where input(age, 8.) in (&age)

When you write

 "&age" 

SAS creates single string with all values and commas inside, which is not what we need for IN operator.

Added. This is my code that works:

%let age = 12,34,56;
%put &age;

data family;
  input age @@;
  datalines;
15 16 17 12 33 34 55 56
;
run;

proc sql;
  select *
  from family
  where age in (&age);
quit;