0

In file a.txt containing "abc", I want to replace "abc" with a 20000-length string. I could use Stata command filefilter for converting ASCII text or binary patterns in a file to do it. How to do it in SAS?

a.txt contents:

   {\rtf1
    {\fonttbl{\f1\fmodern\fcharset134;}}
    {\info}
    \sectd\pgwsxn11907\pghsxn16840\marglsxn1418\margrsxn1418
    \margtsxn1440\margbsxn1440\sectdefaultcl
    \headery851{\header\pard\qr\fs18\par}
    \footery992{\footer\pard\qc\f0\fs18\chpgn\par}
    {\pard\qc\sb30\sa30\fs21 \par
    \trowd\trautofit1\trgaph0\trleft-75\intbl\trqc           
    \clbrdrt\brdrs\brdrw30\clbrdrb\brdrs\brdrw10\clvertalc\cellx6993\clbrdrt
    \brdrs\brdrw30\clbrdrb\brdrs\brdrw10\clvertalc\cellx13986\clbrdrt\brdrs\brdrw30
    \clbrdrb\brdrs\brdrw10\clvertalc\cellx20979
    \qc\fs21 x\cell\qc\fs21 y\cell\qc\fs21 z\cell\row
    \trowd\trautofit1\trgaph0\trleft-75\trqc                  
    \clvertalc\cellx6993\clvertalc\cellx13986
    \clvertalc\cellx20979
    \qc\fs21 a\cell\qc\fs21 b\cell\qc\fs21 abc\cell\row
    \trowd\trautofit1\trgaph0\trleft-75\intbl\trqc   
    \clbrdrb\brdrs\brdrw30\clvertalc\cellx6993\clbrdrb\brdrs\brdrw30
    \clvertalc\cellx13986\clbrdrb\brdrs\brdrw30\clvertalc\cellx20979
    \qc\fs21 d\cell\qc\fs21 e\cell\qc\fs21 f\cell\row
    }}
Nick Cox
  • 35,529
  • 6
  • 31
  • 47
stata
  • 513
  • 2
  • 6
  • 12
  • 2
    If you're not otherwise using this in SAS, SAS is a poor tool for this purpose. What is the scope around this - why do you want to use SAS? Are you then reading it into a dataset or something else, or is this solely changing a .txt file? – Joe Jan 22 '14 at 18:26
  • What operating systems are you using? On a UNIX-based machine, you can call shell commands in SAS like this: `x perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' a.txt`. – dimitriy Jan 22 '14 at 22:42
  • Thank you. Operating system is Windows – stata Jan 23 '14 at 03:28

1 Answers1

0

There are suggestions for some tools here that will work on Windows.

One you have a tool like FART or sed installed, you can use x as prefix in SAS to access the command line like this.

Community
  • 1
  • 1
dimitriy
  • 9,077
  • 2
  • 25
  • 50