BookmarkSubscribeRSS Feed
EinarRoed
Pyrite | Level 9

I have a macro parameter named &input_key. It can contain values like these:

- "CASE_ID"

- "EMAIL_ID"

- "CUSTOMER_ID, BANK_ID"

 

When it contains 2 comma-separated values (like in the 3rd line above), I need to split them. Basically I want to say this in a SAS data step:

 

IF &input_key. contains "," THEN

     %let &input_key_1 = scan(&input_key, 1, ",");

     %let &input_key_2 = scan(&input_key, 2, ",");

ELSE &input_key.;

 

Can someone please assist in how to properly write this code?

2 REPLIES 2
user24feb
Barite | Level 11

Try:

%Let input_key = CUSTOMER_ID, BANK_ID;
Data _NULL_;
  Do i = 1 To Count("&input_key", ",") +1;
    Call SymputX(CatS("input_key_", Put(i, Best.)), Scan("&input_key", i, ","));
  End;
Run;
%Put **&input_key_1.**&input_key_2.**;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This shows an example:

%let input_key=CUSTOMER_ID, BANK_ID;

%put %scan(%quote(&input_key.),1,%str(,));
%put %scan(%quote(&input_key.),2,%str(,));

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5658 views
  • 2 likes
  • 3 in conversation