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

Typically, I run my program with only one value assigned to a macro variable as such:

%let Client = 'BCBSFL';

Client is later referenced as such:

proc sql noprint;
	select distinct NDC_Num format = $quote13. into :Specialty separated by ','
		from pcom1.TRIESSENT_FEE_SCHEDULE (where= (Clnt_CD = &Client));
		run; 

I want my code to be more versatile to handle a list of values (all Clients) rather than a single value. Note: there are many places where the macro variable Client is referenced, so I'd prefer not to simply have an in list wherever Client is referenced.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Consider a slight change to your program, in the WHERE clause:

 

where = (Clnt_CD in (&client))

 

This works for either a single item or a list:

 

%let Client = 'BCBSFL';

%let Client = 'BCBSFL' 'BCBSNH';

 

Note that commas are not required.

 

The more difficult question is what else you want to do with &CLIENT.  How else will your program be using it.  You may need to learn a little more macro language to take a list of values and select one of them at a time.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Personally my opinion is don't.  Datasets are there to keep "data" items.  For instance:

data params;
  val="Acura"; output;
  val="Audi"; output;
run;
proc sql;
  create table WANT as
  select  *
  from    SASHELP.CARS
  where   MAKE in (select VAL from PARAMS);
quit;
  

Your "list of data" is stored in a dataset, this is queried in the SQL clause as a subquery.  Simple Base SAS code, easy to maintain/understand and expand upon, and you can use all Base SAS processing on your parameters.

 

ballardw
Super User

If you don't want a "list" as used then perhaps a different variable that does contain the list of clients and then loop over them?

Or a dataset with the client values and then use a Datastep and call execute to generate the code for each value.

 

The first might be easier to adapt to your code.

Astounding
PROC Star

Consider a slight change to your program, in the WHERE clause:

 

where = (Clnt_CD in (&client))

 

This works for either a single item or a list:

 

%let Client = 'BCBSFL';

%let Client = 'BCBSFL' 'BCBSNH';

 

Note that commas are not required.

 

The more difficult question is what else you want to do with &CLIENT.  How else will your program be using it.  You may need to learn a little more macro language to take a list of values and select one of them at a time.

JediApprentice
Pyrite | Level 9

Thank you, @Astounding. My program is only using Client in where conditions like in my example, so no need to loop through the list, so this solution seems to be the simplest. Thank you all for your help! Much appreciated.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 3675 views
  • 0 likes
  • 4 in conversation