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 (December 2001, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 21 Dec 2001 08:52:24 -0500
Reply-To:     Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject:      Re: Using sas to automate file editing.
Comments: To: seeliger <seeliger@MERCURY.COR.EPA.GOV>
Content-Type: text/plain; charset="iso-8859-1"

Curt,

One small note first: if you don't want to lose your leading blanks, you need to use $CHAR80. rather than just $80. in your PUT statement.

The real problem is with the "edit in place". If you look at the SAS log after your job runs, you will see something like the following: NOTE: 3 records were read from the infile FREF. The minimum record length was 4. The maximum record length was 16. NOTE: 3 records were written to the file FREF. The minimum record length was 80. The maximum record length was 80. The very different input and output record lengths is your clue that something is very wrong. Your file has varying-length records, which is generally the case with text files in a Windows environment. Invisible line delimiter characters (CR-LF) are used by SAS and other software to determine where lines (records) begin and end, rather than each line being a fixed length. On the other hand, you are writing back 80 bytes each time, so naturally things are going to wind up in a mess.

Bottom line -- it's almost always a bad idea to edit such files "in place". I'd recommend first outputting to a junk file, then copying back from the junk file back to the real file. That way you can maintain the same file name while getting correct results. See example below.

Of course, if the original files you're editing can't be easily recreated, there's a lot to be said for making sure they are backed up before you change them ...

Mike Rhoads Westat RhoadsM1@Westat.com

FILENAME fref 'c:\junk\aardvark.txt'; FILENAME junk "%SYSFUNC(PATHNAME(WORK))\junk.txt";

DATA _NULL_; INFILE fref; FILE junk; INPUT; /* Add *** at beginning of each line */ _INFILE_ = '***' || _INFILE_; PUT _INFILE_; RUN;

DATA _NULL_; INFILE junk; FILE fref; INPUT; PUT _INFILE_; RUN;

-----Original Message----- From: seeliger [mailto:seeliger@MERCURY.COR.EPA.GOV] Sent: Thursday, December 20, 2001 8:23 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Using sas to automate file editing.

On Thu, 20 Dec 2001, Jack Hamilton wrote:

> If you specify only a variable name in the PUT statement, you'll get > list format by default. List format left-aligns variables. Try > > put @1 line; > > That will force formatted mode, and the blanks won't be stripped: > > ----- > 9 data _null_; > 10 infile cards; > 11 input; > 12 line = _infile_; > 13 put _infile_; > 14 put line; > 15 put line $80.; > 16 put @1 line $80.; > 17 put line $char80.; > 18 cards; > > blanks before this! > blanks before this! > blanks before this! > blanks before this! > blanks before this! > -----

Thanks for the quick reply! This is close, as it works when writing to the log, but not when I edit in place, as with this code,

FILENAME fref '~/temp/test.test';

DATA _NULL_; LENGTH line $200;

INFILE fref SHAREBUFFERS; FILE fref; INPUT; line=_infile_; PUT @1 line $80.; RUN;

which changes this text:

/* _aardvark.sas

This SAS code is developed and used by the EPA WED NHEERL in Corvallis, Oregon. It is intended to assist in the validation of EMAP and REMAP physical habitat data, and follows the guidelines given in "Quantifying

To this gooy mess:

/* _aardvark.sas Corvallis, EMAP

is intended to assist the investigator's efforts by comparing related om different field forms or different parts of the same form, and

Which just isn't right. Near as I can tell, only the INFILE and FILE statments are different.

nuts.

cur


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