2

Hi, I have the following sample data:

custid 
100 
200 
300 
400 
500 
. 
. 
etc.

I want to build the following string:

where custid in (100, 200, 300, 400, 500.....)

I have SAS 8.21 installed at my location. What is the best way to accomplish this? Thanks.

flag

1 Answer

6

/*- Setup your data -*/
Data start; 
input custid; 
cards; 
100 
200 
300 
400 
500 
run; 

proc sql noprint;
/*- Get the List into a Macro Var --*/
select distinct custID
into :IDList separated by ','
from Start;
/*-- now put it into your code gen template --*/
create table String
as select "Where CustID in (&IDList)" as String_You_Want
from Start (obs=1);
quit;
link|flag
I'd also suggest adding a distinct clause into the select statement in case there are duplicate values. – cmjohns Nov 4 at 15:58
done. good catch. – jay.l.stevens Nov 4 at 16:33

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.