afiqjohari
afiqjohari

Reputation: 241

SAS reading data containing more than one delimiter

26/03/2012~19:45:58~1~1636~00000000000000000000~41.45~17~16;
28/03/2012~19:45:58~1~1636~00000000000000000000~41.45~17~6;
29/03/2012~19:45:58~1~1636~00000000000000000000~41.45~17~1;
23/03/2012~19:45:58~1~1636~00000000000000000000~41.45~17~4;
25/03/2012~19:45:58~1~1636~00000000000000000000~41.45~17~9;
27/03/2012~19:45:58~1~1636~00000000000000000000~41.45~17~880;

I have this data to read. While it's clear that the delimiter is "~", I got a problem to read the last column of an observation because of the ";"

How can I ask SAS to read the 16, 6, 1, 4, 9, 880 and not the ";" ? Thanks

Upvotes: 1

Views: 2869

Answers (2)

Robbie Liu
Robbie Liu

Reputation: 1511

Just specify ';' in the delimiter statement, along with '~'

data test;
infile "/path/to/file" delimiter='~;';
input var1 $ var2 $ var3-var7 var8;
run;

Upvotes: 6

DavB
DavB

Reputation: 1696

You could read in the ';' and then strip it out using the compress function:

a=compress(b,";");

You'll probably want a numeric:

a=input(compress(b,";"),best.);

If I was doing this I might use the INFILE variable along with the SCAN function:

data mydata;
  infile "/path/to/my/file";
  input;
  rogue_var=scan(_infile_,-1,"~;");
  rogue_var_num=input(scan(_infile_,-1,"~;"),best.);
run;

Note that the "-1" as the SCAN function's second parameter means we take the first word from the end of the line.

Upvotes: 2

Related Questions