Date: Tue, 5 Mar 2002 11:45:13 -0500
Reply-To: "David L. Ward" <dward@SASHELP.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Ward" <dward@SASHELP.COM>
Subject: Re: Replacing a string in a file
In-Reply-To: <001001c1c463$ee4e4d80$b87e1e42@w8k4o4.ne.mediaone.net>
Content-Type: text/plain; charset="iso-8859-1"
Basically, recfm=N will disregard line breaks when reading data. This is
useful if you have either binary data or extremely long lines that you want
to be able to read using multiple input statements and not worry about
record length. With this format there are no "records", but the length of
the data you can read in one input statement is controlled using lrecl.
Thus in this case the trailing @ symbols won't make much difference since
there's no such thing as a record.
But correct me if I'm wrong! I haven't looked at this stuff in several
years. The reason I'm doing this now is that I am still trying to use a
"template" for printing form data. A client has a word document we can save
either as RTF or PCL that needs substitutions made (like address, name,
etc.). We need to then send it to the printer in a server environment.
David
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of Robert
Virgile
Sent: Tuesday, March 05, 2002 11:37 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Replacing a string in a file
David,
Maybe using recfm=N takes care of these issues ... I'm not familiar with it.
Two changes to consider:
1. Add the truncover option to the infile statement:
infile 'c:\temp\temp.txt' recfm=N truncover;
If the incoming line contains fewer than 100 characters, the input statement
will take whatever is there.
2. Hold the line with a trailing @ sign, so later iterations of the input
statement read from the same line:
input chunk $char100. @;
Other infile statement options may help. One such option (I forget its
name) measures the length of the incoming data line. Another (lrecl=) may
be needed to access long incoming records.
Like I said, I'm not familiar with recfm=N and its implications, but any of
the above tools may come into play.
Good luck.
Bob V.
-----Original Message-----
From: David L. Ward <dward@SASHELP.COM>
Newsgroups: bit.listserv.sas-l
To: SAS-L@LISTSERV.UGA.EDU <SAS-L@LISTSERV.UGA.EDU>
Date: Tuesday, March 05, 2002 10:49 AM
Subject: Replacing a string in a file
>Hi all, before I spend too much time on this, what is the best way to
>replace all occurrences of a string with another in a binary file? Assume
>we want v6 compatibility (200 char string limit). The complication that
>arises is that if you read the binary file in 200 character chunks, the
>boundary of your chunks may occur in the middle of the search string.
Plus,
>if your chunk is comprised of too many search strings, the replacements (if
>longer than the search strings) may make the length of the string longer
>than 200 characters.
>
>The file needs to be binary so don't assume I can solve this by doing
>line-based reading and writing. I'm trying to replace strings in a variety
>of file formats, PCL, RTF (which can be line based, I know, but I'd rather
>stick with an exact copy of the file just with the replacements), etc.
>Besides, binary data is like reading one LONG line.
>
>This is the blind-man's approach. There are many problems I won't point
out
>but I'm sure they will be obvious to most of you.
>
>data _null_;
> length chunk $200;
> infile 'c:\temp\temp.txt' recfm=N;
> file 'c:\temp\temp2.txt' recfm=N;
> input chunk $char100.;
> chunk=tranwrd(chunk,'Default','Replacement');
> put chunk $char100.;
>run;
>
>Thanks for any help!
>
>David W