|
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of ST
> Sent: Thursday, September 15, 2011 12:45 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Need help for infile statement
>
> Hi there,
>
> I have to read a file which use '|~' as the delimiter, three variables,
> the
> dataset has three variables: V1(CHAR2), V2(CHAR10), V3(CHAR17), like
> this
>
> C|~26248476|~20028102659054000|~
> T|~26248484|~20028102659062000|~
> |~26248490|~20028102659068000|~
> B|~26248497|~20028102659076000|~
>
> Here is my code:
> data base;
> infile 'id.txt' MISSOVER DLMSTR="|~" DSD;
> length
> V1 $2
> V2 $10
> V3 $17
> ;
> input
> V1 $
> V2 $
> V3 $
> ;
> run;
> Proc print; run;
>
> the V2 of the 3rd obs is not correct.
>
> Result:
> Obs V1 V2 V3
>
> 1 C 26248476 20028102659054000
> 2 T 26248484 20028102659062000
> 3 ~26248490 20028102659068000
> 4 B 26248497 20028102659076000
>
>
> now what I can do is to use
> infile 'id.txt' MISSOVER DLM="|" DSD;
>
> Result:
> Obs V1 V2 V3
>
> 1 C ~26248476 ~2002810265905400
> 2 T ~26248484 ~2002810265906200
> 3 ~26248490 ~2002810265906800
> 4 B ~26248497 ~2002810265907600
>
>
> and use substr function to get rid of the first character from V2 and
> V3.
>
> Any suggestions to read without using substr function?
>
> Thanks in advance,
>
> Hu
Data _Null_ has given you an explanation. Here is a workaround. Just use a single delimiter and compress the other delimiter out of the _infile_ variable.
data base;
infile cards DLMSTR="|" dsd;
length V1 $2 V2 $10 V3 $17;
*--get rid of the tilde character--*;
input @;
_infile_ = compress(_infile_,'~');
*--now input you variables--*;
input V1 $ V2 $ V3 $ ;
cards;
C|~26248476|~20028102659054000|~
T|~26248484|~20028102659062000|~
|~26248490|~20028102659068000|~
B|~26248497|~20028102659076000|~
;
run;
Hope this helpful,
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
|