Re: Help in reading a flat file. #2

  • Follow


Hi=A0Paul Choate & Data _null_,=A0=A0 =A0 =A0Thank you very much for your h=
elp on this.Now I am at home and dont have SAS at my home. so I am not able=
 check your example codes.=A0
I forgot to tell you one more information,the flat file will have two field=
s with=A0delimiter=A0"~"i can read the first record as it will always be 10=
 character, the second value will have=A0multiple commas "," multiple blank=
 spaces, multiple enter characters and will be there in multiple=A0=A0lines=
..
I am hoping=A0RECFM=3DN would help me this.if not please advise on this.
Once again Thanking for your time and efforts on this.
Thanks 'n' Regards=20
alex .S.

--- On Fri, 11/12/09, Choate, Paul@DDS <Paul.Choate@DDS.CA.GOV> wrote:

From: Choate, Paul@DDS <Paul.Choate@DDS.CA.GOV>
Subject: Re: Help in reading a flat file.
To: SAS-L@LISTSERV.UGA.EDU
Date: Friday, 11 December, 2009, 10:31 PM

Hi Alex -

This might be due to delimiters in your text - SAS has no problem reading a=
 $30,000 var:

filename test 'test.txt' lrecl=3D40000;
data _null_;
file test;
put @1 '0123456789'
=A0 =A0 @12 3000*'0123456789';
run;
data readit;
infile test;
input @01 var1 $10.
=A0 =A0 =A0 @12 var2 $30000.;

lenv2=3Dlength(var2);
put lenv2=3D;
put var2=3D;
run;


Note what happens when CRLFs are embedded:

filename test 'test.txt' lrecl=3D40000;
data _null_;
file test;
weirdchars=3D'CRLF'||'0D0A'x||'Tab'||'09'x;
put @1 '0123456789'
=A0 =A0 @12 3000*weirdchars;
run;

data readit;
infile test;
input @01 var1 $10.
=A0 =A0 =A0 @12 var2 $30000.;
lenv2=3Dlength(var2);
put lenv2=3D;
put var2=3D;
run;


But you can read the data as a stream using recfm=3Dn and specifying an lre=
cl:

filename test 'test.txt' lrecl=3D40000;
data _null_;
file test;
weirdchars=3D'CRLF'||'0D0A'x||'Tab'||'09'x;
put @1 '0123456789'
=A0 =A0 @12 3000*weirdchars;
run;

data readit;
infile test recfm=3Dn lrecl=3D40000;
input @01 var1 $10.
=A0 =A0 =A0 @12 var2 $30000.;
lenv2=3Dlength(var2);
put lenv2=3D;
put var2=3D;
output;
stop;
run;


Another approach would be to pre-process the file and strip out the embedde=
d line feeds.

data _null_;
=A0=A0=A0infile 'test.txt' recfm=3Dn;
=A0=A0=A0file 'test.txt' recfm=3Dn;
=A0=A0=A0input byte $char1. @;
=A0=A0=A0if byte ne '0A'x then put=A0 byte $char1. @;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else put '20'x=A0=A0=A0@;
run;
data readit;
infile test;
input @01 var1 $10.
=A0 =A0 =A0 @12 var2 $30000.;

lenv2=3Dlength(var2);
put lenv2=3D;
put var2=3D;
run;


hope that helps.

Paul Choate






________________________________________
From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] On Behalf Of Alex S [alex4=
sas@YAHOO.CO.IN]
Sent: Friday, December 11, 2009 6:11 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Help in reading a flat file.

Hi All,=A0 =A0 =A0 I have a flat file with one record (two fields on it), o=
ne with 10 character another one with 30,000 characters.I want to write the=
se two fields on a data set. The data set should have one record and two fi=
elds.
When read this flat file I am getting more than one records,it seems the 30=
,000 characters are split into several records.
Could you please help me on this.
Thanking you in advance.
Thanks 'n' Regards
alex .S.


=A0 =A0 =A0 The INTERNET now has a personality. YOURS! See your Yahoo! Home=
page. http://in.yahoo.com/
=0A=0A=0A      The INTERNET now has a personality. YOURS! See your Yahoo! H=
omepage. http://in.yahoo.com/
0
Reply alex4sas (68) 12/11/2009 5:52:38 PM


0 Replies
300 Views

(page loaded in 0.025 seconds)

Similiar Articles:













7/22/2012 6:52:48 PM


Reply: