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 (November 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 16 Nov 2006 11:58:33 -0500
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: Replacing variable names in text
Comments: To: BruceBrad <b.bradbury@unsw.edu.au>
In-Reply-To:  <1163674756.020132.46840@b28g2000cwb.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 11/16/06, BruceBrad <b.bradbury@unsw.edu.au> wrote: > input dummy $ 1-1 @; /* assigns linelength, @ holds to read line > again */ > input @1 line $varying500. CurrentLineLength;

There is no need to "prime the pump" the value assigned to the INFILE variable associated with the LENGTH option is the value for the line that is being read.

Consider this output.

107 data _null_; 108 infile temp length=CurrentLineLength; 109 input @1 line $varying500. CurrentLineLength; 110 put 'This value equals that reported by LIST statement: ' CurrentLineLength=;

111 list; 112 run;

NOTE: The infile TEMP is: File Name=F:\Temp\SAS Temporary Files\_TD3256\#LN00011, RECFM=V,LRECL=256

This value equals that reported by LIST statement: CurrentLineLength=1 RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 1 A 1 This value equals that reported by LIST statement: CurrentLineLength=2 2 AB 2 This value equals that reported by LIST statement: CurrentLineLength=3 3 ABC 3 NOTE: 3 records were read from the infile TEMP. The minimum record length was 1. The maximum record length was 3.

I'm not sure I completely understand your needs but a regular expression may be more useful than TRANWRD. Do RXCHANGE when the target is found in the line. Consider the following.

data work.nameChange; infile cards eof=eof; input (old new) (:$32.); output; return; eof: call symput('ArrayDim',trim(put(_n_-1,best.-l))); return; cards; K1CA5P1 New1 K1CA5P2 New2_LongName ;;;; run;

data _null_; attrib WorkingInfile length=$32767; * need due to truncation when _INFILE_ used in RXCHANGE; array _rx[&arrayDim] _temporary_; do _n_ = 1 by 1 until(eof); set work.nameChange end=eof; _rx[_n_] = rxparse(trim(old)||' to '||quote(trim(new))); end; do while(1); infile cards eof=eof; input; WorkingInfile = _infile_; put / 'Before: ' WorkingInfile; do _n_ = 1 to dim(_rx); if rxmatch(_rx[_n_],WorkingInfile) then call rxchange(_rx[_n_],99,WorkingInfile); end; put 'After: ' WorkingInfile; put; end; eof: do _n_ = 1 to dim(_rx); call rxfree(_rx[_n_]); end; stop; cards4; A K1CA5P1 this is more stuff. AB K1CA5P2 K1CA5P2 K1CA5P2 AB AB AB ABC K1CA5P2 K1CA5P1 K1CA5P3 ABC ABC a k1ca5p1 this is more stuff. ab k1ca5p2 k1ca5p2 k1ca5p2 abc k1ca5p2 k1ca5p1 k1ca5p3 A K1ca5P1 this is more stuff. AB K1CA5p2 K1CA5P2 K1CA5P2 ABC K1ca5P2 K1CA5P1 K1ca5P3 data _null_; * input file; infile "&workdir.\&infile..sas" length=CurrentLineLength missover; * output file; file "&workdir.\&infile._NEW.sas";

input dummy $ 1-1 @; /* assigns linelength, @ holds to read line again input @1 line $varying500. CurrentLineLength;

* initialise; length OutputLine $ &MaxLineLen; if CurrentLineLength>&MaxLineLen then error "Increase line length"; length word $ &MaxInputVarnameLen; length newword $ &MaxOutputVarnameLen; loop across every string ;;;; run;


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