DATA Step, Macro, Functions and more

Creating a Macro that populates a set within PROC SQL

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Creating a Macro that populates a set within PROC SQL

Is it possible to replace this statement within PROC SQL:

 

case when variable in ('1', '2', '3', '4') then ....

 

with a macro of the form

 

case when variable in (%macroname(4)) then ...

 

So the macro would populate the set with the positive integers (in character form) 1 through 4 (or any positive number in place of 4).

 

Thanks, and sorry if this has been asked before.


Accepted Solutions
Solution
‎08-22-2016 04:15 PM
Super User
Posts: 5,499

Re: Creating a Macro that populates a set within PROC SQL

[ Edited ]
Posted in reply to Jeremy_Wade

While it is very possible in any case, it is easier if you are willing to:

 

  • Use double quotes instead of single quotes
  • Skip the commas entirely (the WHERE clause should work either way)

 

Here is one possible approach using the simplifying assumptions above:

 

%macro macroname (limit);

 

%local i;

%do i=1 %to &limit;

   "&i"

%end;

 

%mend macroname;

View solution in original post


All Replies
Solution
‎08-22-2016 04:15 PM
Super User
Posts: 5,499

Re: Creating a Macro that populates a set within PROC SQL

[ Edited ]
Posted in reply to Jeremy_Wade

While it is very possible in any case, it is easier if you are willing to:

 

  • Use double quotes instead of single quotes
  • Skip the commas entirely (the WHERE clause should work either way)

 

Here is one possible approach using the simplifying assumptions above:

 

%macro macroname (limit);

 

%local i;

%do i=1 %to &limit;

   "&i"

%end;

 

%mend macroname;

New Contributor
Posts: 2

Re: Creating a Macro that populates a set within PROC SQL

Posted in reply to Astounding

Awesome, Thanks!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 219 views
  • 1 like
  • 2 in conversation