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 (August 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 6 Aug 2004 16:53:24 -0400
Reply-To:     Quentin McMullen <mcmullen@ALEXANDER.STAT.BROWN.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Quentin McMullen <mcmullen@ALEXANDER.STAT.BROWN.EDU>
Subject:      Re: flat file modification
Comments: To: Mike Rhoads <RHOADSM1@WESTAT.com>
In-Reply-To:  <446DDE75CFC7E1438061462F85557B0F0458BD67@remail2.westat.com>
Content-Type: text/plain; charset="us-ascii"

Thanks Mike,

So you're suggesting that I'm not supposed to be a SAS programmer, I'm supposed to be a programmer who uses SAS, right? I can't forget about all them bits and bytes? I suppose had I stayed at SAS Mecca, by now I would have taken that C class Sig suggested I take, just to learn some perspective on/ understanding of my SAS code....

Your explanation makes sense, and matches with what a colleague told me.

That said, I got an off-list suggestion of from Randy Rak [rrak_at_ilexonc.com], kind enough to steer me toward: infile "c:\junk1.txt" recfm=f lrecl=100; file "c:\junk1.txt" recfm=f lrecl=100;

Which seems to do what I want in Windows world (I do get an extra line at the end...).

I'm still not close enough to being a real programmer to have a solid understanding of how this is doing the memory magic (I've got some theories) but Friday at 4:30pm before a week's vacation, it's good enough for me. : )

For those curious, I am doing this in order to post-process some RTF code produced by ODS.

Thanks to all, --Quentin

-------------------------------- Quentin McMullen Center for Statistical Sciences Brown University, Box G-H 167 Angell Street, 3rd floor Providence, RI 02912 voice: 401-863-1164 fax: 401-863-9182 e-mail: mcmullen@stat.brown.edu --------------------------------

> -----Original Message----- > From: Mike Rhoads [mailto:RHOADSM1@WESTAT.com] > Sent: Friday, August 06, 2004 3:10 PM > To: 'Quentin McMullen'; SAS-L@LISTSERV.UGA.EDU > Subject: RE: flat file modification > > > Quentin, > > I always hate to say "You can't do that" on this list, > because there are many sharp folks who can typically find > several ways that you CAN. ;-) > > However, let me be brave here and say "You can't do that", > where "that" is defined as "modifying a flat file in place by > inserting text without losing anything." > > The file is just a series of bytes on the disk, which special > bytes to determine where each "record" ends and where the > useful data for the entire file ends. So, under Windows > where 2 bytes (carriage-return and line-feed) separate each > record, you would start out with: > > I am the first test record~^I am the second test record~^I am > the third record~^\ > > where I'm using ~ to represent CR, ^ to represent LF, and \ > to represent the "control Z" end-of-file character. (Not > sure whether you'd have all 3 at EOF, or just the \.) > > Inserting characters would have to shift everything else in > the file down by the number of inserted characters, which is > not really a modification in place -- everything following > the insertion in the file has to change/move. It's like SAS > or some other text editor or word processor in overtype mode. > Or think of it as being like one of those CD holders with > slots, where you have put all your CDs alphabetically, one > per slot, with no empty slots. If you go out and buy 2 more > Springsteen CDs, to put them in the right place you would > either have to move all of the CDs later in the alphabet down > 2 slots, or take out the 2 CDs where the new ones would go > and just toss them on the couch. > > That's the best explanation I can come up with on a Friday > afternoon -- hope it helps some. > > Mike Rhoads > Westat > RhoadsM1@Westat.com > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of Quentin McMullen > Sent: Friday, August 06, 2004 2:00 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: flat file modification > > > Thanks boss, > > But I think I wasn't clear. > > In this case I do want to insert some text into the middle of > a line in the flat file. So I want that line to become > longer, and I'm happy with line > #1: > > > I am the best first test record > > But I'm not happy with the line after that, which is lacking "I am": > > > the second test record > > Your suggestion changes from a text insertion problem to a > text replacement problem (largely my fault for providing a > poor example). > > Kind Regards, > --Quentin > > > > > -----Original Message----- > > From: Sigurd Hermansen [mailto:HERMANS1@WESTAT.com] > > Sent: Friday, August 06, 2004 1:48 PM > > To: 'Quentin McMullen'; SAS-L@LISTSERV.UGA.EDU > > Subject: RE: flat file modification > > > > > > Quentin: > > _infile_=substr(_infile_,1,9)||'best '||substr(_infile_,10+5); > > ----- > > ^ offset by > > length of insert. > > Once you concatenate a string of length 5 in the line, the pointer > > argument in the next substr() function points to the 10th (in this > > case) character in the augmented string. The offset advances the > > pointer beyond the insert to the string that follows the > insert. Sig > > -----Original Message----- > > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of > > Quentin McMullen > > Sent: Friday, August 06, 2004 1:19 PM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: flat file modification > > > > > > Hi All, > > > > I am attempting to modify a single line of a flat file by inserting > > some text into the middle of it. Below, I insert some text > into line > > #1 of a file (modifying the file in-place). To my horror, > line 2 is > > modified as well. It looks like when I add 5 characters to > line #1, > > somehow something wraps (?) and the first 5 characters from line #2 > > are deleted. Anyway, I've tried my usual flat-file random > > guesses (lrecl? pad? truncover?) and some new to me > > (sharebuffers), with no joy. > > > > No doubt the problem is obvious to a flatfile maven out there? > > > > data _null_; > > file "c:\junk1.txt"; > > put "I am the first test record"; > > put "I am the second test record"; > > put "I am the third record"; > > run; > > > > data _null_; > > infile "c:\junk1.txt" ; > > file "c:\junk1.txt" ; *modify in place (real problem is a > > big file, > > modifying one line); > > input; > > if index(_infile_,"the first") then do; > > _infile_=substr(_infile_,1,9)||'best '||substr(_infile_,10); > > put _infile_; > > end; > > stop; > > run; > > > > data _null_; > > infile "c:\junk1.txt"; > > input; > > put _infile_; > > run; > > > > Result: > > I am the best first test record > > the second test record > > I am the third record > > > > Kind Regards, > > --Quentin > > >


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