Help using Base SAS procedures

Process to handle multiple quotes

Reply
Frequent Contributor
Posts: 131

Process to handle multiple quotes

data test (keep=ln_no BO_BORR_FST_NM

     BO_BORR_LAST_NM BO_BORR_MDL_NM BO_BORR_NM YE_BORR_ID_NO);

     set data1;

     if ye_borr_id_no in ('9897'

                                '4231'

                                '6240'

                                '3708'

                                '9517');run;

Is there an alternative process to include all of the numbers in quotes without having to physically place quotes between all values.  For example '9897'.  I have about 900 of these to place after the ye_borr_id_no.  I know I can do a table using cards like this

data test;

input id_no $4.;

cards:

9897

etc........;

run;

I just need to perhaps incorporate this into the datastep.

Super Contributor
Posts: 275

Re: Process to handle multiple quotes

Use quote function

Super User
Posts: 17,801

Re: Process to handle multiple quotes

Create the table test and use a SQL query instead:

proc sql;

create table want as

select *

from data1 where ye_borr_id_no in (select  id_no from test);

quit;

Super User
Super User
Posts: 6,499

Re: Process to handle multiple quotes

For 900 you are better off using a data set and using SQL or MERGE to do the sub setting.

But if you want to generated quoted list from space delimited list than TRANWRD can help.

%let list=9897 4231 6240 ;

%let qlist="%sysfunc(tranwrd(&list,%str( )," "))";

%put &qlist;

Super User
Posts: 10,490

Re: Process to handle multiple quotes

And yet another way:

proc format library=work;
value $mylist
9897,
4231,
6240,
3708   = 'Valid'
;
run;

data _null_;
do x= '9897','5555';
if put(x,$mylist.)='Valid' then put 'In list';
else put 'not in list';
end;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 217 views
  • 0 likes
  • 5 in conversation