BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
Data application (keep=org_code application_ref_no application_no credit_card_no applicant _id);
Set onenov.application (encoding=any);
Where credit_card_no in (’0004835199841570016’, ’0004835191842460016’,
’0000235881284822010’, ...) /* plus another 17 similar codes*/
Run;

I have the above code but strangely in the output I get credit no wrong for those not end in 0
Eg 0004835199841570016 becomes
0004835199841570010

While those end in zero is correct

Is the format issue?
6 REPLIES 6
HeatherNewton
Quartz | Level 8
Oh I tested again with only 6 codes and it works fine

What is the best way to do using many ORs instead in (,.,.,.,.,.)?
ballardw
Super User

SHOW the format and length associated with the variable. If you don't know how to find that then run:

Proc contents data=onenov.application;
run;

and share the results. There may be issues with the data.

Also, any time you have questions about code behavior you should copy the code and all messages from the log and paste that into a text box. Sometimes there are messages about data conversion. Also if you have errors then a possible previous data set might be what you are looking at, not the results of this particular code.

 

Also be aware that the code you pasted shows single quotes that are curly or "smart quotes" see: (’0004835199841570016’,

These cause errors. You want to make sure that the values use the simple quote ' as typed form the keyboard. They may appear as curly because of pasting into the main message window, which on this forum will reformat pasted text. It is a good idea to paste code or log entries into a text box opened on the forum with the </> icon to prevent such.

An example of what the wrong quote can do:

333  data example;
334     set junk;
335     where credit_card_no=’0004835199841570016’;
                             -
                             22
                             76
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
              a numeric constant, a datetime constant, a missing value, (, *, +, -, :, INPUT,
              NOT, PUT, ^, ~.

ERROR 76-322: Syntax error, statement will be ignored.

336  run;

 

HeatherNewton
Quartz | Level 8

if I just want a subset of the dataset, what is the best way to write where

if I have many variables and I only want the the following:

org_code='301', account_no='1234567890123456'

org_code -'251', account_no=9876543210123456'

...

 

can I write:

 

where

org_code='301' and account_no='1234567890123456'

or

org_code='251' and account_no='9876543210123456'

or

...

(and 20 more pairs...) ;

 

 

 

ballardw
Super User

You want to ( ) around the Pairs to make sure they are considered as such.

where
   ( org_code='301' and account_no='1234567890123456' )
   or
   ( org_code='251' and account_no='9876543210123456')
   or
   ( <continue the pattern>)

If, and this is a big if, your data is nice about combinations that occur in your data you might be able to use shorter code such as

where 
    org_code in ('301'  '251' <other codes>)  and account_no in ('1234567890123456'  '9876543210123456' <other accounts>)

This may be possible if you know, meaning have checked, that org_code ='301' never appears with any of the account_no except '1234567890123456'. This would select org_code='301' and account_no='9876543210123456' if it occurs for example.

 

Please post code in text boxes opened using the </> icon.

That could be checked by any number of methods

Tom
Super User Tom
Super User

You could convert the pairs into a single string so you could use IN

where catx('|',org_code,account_no) in
 ('301|1234567890123456'
  '251|9876543210123456'
  ...
 )

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 504 views
  • 1 like
  • 4 in conversation