sas >> How to replace CRLF with SPACE
by pchoate » Wed, 08 Oct 2003 01:02:16 GMT
Can you explain "length(_infile_)<280" ? Unless byte 280 is blank the infile
should always be 280 if lrecl=280 and recfm=f. The idea behind recfm=f is
that the data is read as a single string, ignoring breaks, so the _infile_
length will always be the lrecl unless it has a blank in the final
position(s).
This seems to work, (notice that the file lrecl is ignored, but the trailing
@ is needed) - the first 20 bytes are read
0,1,2,3,4,5,6,7,8,9,CR,LF,01,2,3,4,5,6,7, the CR,LF is removed, ' ' is
appeded to the end, the line is output with the line-hold specifier, the
process is repeated...
8 data _null_;
9 infile 'C:\Docume~1\pchoate\Desktop\in.txt' lrecl=20 recfm=f;
10 file 'C:\Docume~1\pchoate\Desktop\out.txt' lrecl=20 recfm=f;
11 input;
12 _infile_=compress(_infile_,'0d'x!!'0a'x)!!" ";
13 put _infile_ @;
14 run;
NOTE: The infile 'C:\Docume~1\pchoate\Desktop\in.txt' is:
File Name=C:\Docume~1\pchoate\Desktop\in.txt,
RECFM=F,LRECL=20
NOTE: The file 'C:\Docume~1\pchoate\Desktop\out.txt' is:
File Name=C:\Docume~1\pchoate\Desktop\out.txt,
RECFM=F,LRECL=20
NOTE: 6 records were read from the infile
'C:\Docume~1\pchoate\Desktop\in.txt'.
NOTE: 6 records were written to the file
'C:\Docume~1\pchoate\Desktop\out.txt'.
NOTE: DATA statement used:
real time 0.09 seconds
cpu time 0.00 seconds
in.txt
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
out.txt (all one line)
012345678901234567 8901234567890123 4567890123456789
012345678901234567 8901234567890123 4567890123456789
hth
Paul Choate
DDS Data Extraction
(916) 654-2160
-----Original Message-----
From: Rune Runnestoe [mailto: XXXX@XXXXX.COM ]
Sent: Tuesday, October 07, 2003 7:44 AM
To: XXXX@XXXXX.COM
Subject: How to replace CRLF with SPACE
I want to replace CRLF with SPACE in the file sak. I read the file sak,
and write the result back to a file I have given the name sak_ny
&rf_sd resolves to "F". Every record in the file sak starts with the letter
"S".
I use the following code:
data _null_;
infile sak lrecl=280 recfm=&rf_sd;
file sak_ny lrecl=280 recfm=&rf_sd;
input;
if length(_infile_)<280 and substr(_infile_,1,1)='S' then
do;
_infile_=compress(_infile_,'0d'x!!'0a'x)!!" ";
put _infile_ @;
end;
run;
The problem is that I don't see the expected change in sak_ny. CRLF is
just removed and not replaced by SPACE.
What have I done wrong ?
Regards
Rune Runnestoe