BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jeremy_Wade
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

2 REPLIES 2
Astounding
PROC Star

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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