LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 15 Sep 2011 15:30:06 -0500
Reply-To:     ST <sheepsas@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         ST <sheepsas@GMAIL.COM>
Subject:      Re: Need help for infile statement
In-Reply-To:  <941871A13165C2418EC144ACB212BDB0020A3A60@dshsmxoly1504g.dshs.wa.lcl>
Content-Type: text/plain; charset=ISO-8859-1

Thanks, Data _NULL_ and Dan,

Your answers are really helpful!

Hu

On Thu, Sep 15, 2011 at 3:15 PM, Nordlund, Dan (DSHS/RDA) < NordlDJ@dshs.wa.gov> wrote:

> > -----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 >


Back to: Top of message | Previous page | Main SAS-L page