dwjohnston
dwjohnston

Reputation: 11890

Set fields as missing when importing from CSV

data myout;
infile "&path.\regex.csv" dlm=',';
input fname $ format1 $ format2 $ format3 $; 
run;

My CSV looks like:

field_name, format1, format2, format3
bank_acct, /\d{8}/,,
sort_code, /\d{2}-\d{2}-\d{2}/,,
bank_name, string,,
credit_card, /\d{16}/,,
customer_id, /\s{2}\d{11}/, /\s{1}\d{12}/, /\d{12}/
...

How can I set the fields to missing where they don't have a second and third format?

Upvotes: 1

Views: 109

Answers (1)

BellevueBob
BellevueBob

Reputation: 9618

Add the DSD add TRUNCOVER options to your INFILE statement:

data myout;
   infile "&path.\regex.csv" dlm=',' DSD TRUNCOVER;
   input fname $ format1 $ format2 $ format3 $; 
run;

Data rows that are empty will be set to missing automatically.

Upvotes: 2

Related Questions