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 (June 2002, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 28 Jun 2002 10:20:33 -0400
Reply-To:     "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Organization: MindSpring Enterprises
Subject:      Re: Importing a flat file which has carriage returns in it.
Content-Type: text/plain;

"pobeda" <pobeda1917@hotmail.com> wrote in message news:9j7nhu803t4omsf4o362dc8ar9hv9hmcua@4ax.com... > I have to import a flat file which has a string field of 3000 and in > it there are some carriage returns. > > This gives me some observations which carry over on 2-3 lines. How > can I make SAS understand during the infile statement that this is one > observation ? By the way I use a delimiter='#' to seperate the fields > on that flat file. > > Thanks in advance ! > > pobeda >

Using recfm=N and dlm=# it is as simple as input col1-col10 ;

Example: write an arbitraty text file that 1. is field delimited with # 2. fields do not contain the delimiter 3. fields may contain newline characters 4. fields do not start with a space (eases proof of comparison), if leading spaces were present, they are stripped during input. 5. the last field is followed by a delimiter (other wise how would one know that a newline in the last field is supposed to be a record terminator or part of the data. 6. upon input newlines must be removed from front of data values (the newlines are from the record separator after the last column's field delimiter)

data a; file 'c:\temp\arbitrary.txt' recfm=n;

do row = 1 to 10;

length col1-col10 $100; array col col1-col10;

do i = 1 to 10;

do j = 1 to 100; k = 32 + 96 * ranuni (0); c = byte (k); if c = '#' then c=' ';

if j=1 and c=' ' then c='X'; * presume no column has leading space;

substr (col[i],j,1) = c;

if j < 390 and ranuni(0) < .01 then do; substr (col[i],j,2) = '0D0A'x; * DOS newline in data; end; end;

put col[i] '#'; end; put '0D0A'x; * DOS newline at end of columns of data that might contain DOS newlines; output; end;

keep col1-col10; run;

data b; infile 'c:\temp\arbitrary.txt' recfm=n dlm='#';

length col1-col10 $102;

input col1-col10 ; array col col1-col10;

do i = 1 to 10; if col[i] =: '0d0a'x then col[i] = substr(col[i],3); end; run;

proc compare base=a compare=b; run;

-- Richard A. DeVenezia http://www.devenezia.com/downloads/sas/macros/#sas2xls Use Perl to create an Excel file containing one worksheet per SAS dataset


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