0

The basic trouble is in adding some common data to multiple text files. The output of a SAS program i wrote is many text files in a folder like 30 to 50 text files, now i have to add a mobile number at the top in each file. Right now i do this by manually copying the number and then opening the text files and then pasting the number. Can someone suggest me an alternative way to do this maybe a SAS program or something like that.

Thanks in advance.

H.A
  • 11
  • 4

1 Answers1

0

This program will add the first record to your file (there is no way to 'insert' a new record at the start, the file has to be rebuilt):

%let myfile=C:\temp\MyFile1.sas;
data _null_;
infile "&myfile" ; /* consider using lrecl option if wider than 256 chars */
file "&myfile.";
input; 
if _n_ = 1 then put 'Some Phone Number'; 
put _infile_; 
run;

See the answer to this question for how to get a list of the text files in your folder..

Community
  • 1
  • 1
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • This is the error i am receiving WARNING: Apparent symbolic reference MYFILE not resolved – H.A Feb 19 '14 at 10:59
  • You need to run the first line - "%let myfile=xxx;", and replace xxx with the full path and name of your file. The &myfile variable could then be parametererised in a macro, to loop through your list of files.. – Allan Bowe Feb 19 '14 at 14:04
  • Still unable to get the result i mean the number is not being added to the file ...though the code is running if you dont mind could you plz explain me the role of data _null_; and if _n_=1 in the code. Thanks for all your help. – H.A Feb 20 '14 at 06:10
  • data _null_; file "path and name of the file"; put "99999999"; run; I wrote this and it worked ....once again thanks for your help it would be great if you can still explain me the meaning of the lines i asked above. – H.A Feb 20 '14 at 06:16
  • data _ null _ means we don't create an output dataset (no need, we're using file statement to output a text file instead). _ n _ = 1 tells the data step that we only want to execute the put statement for the FIRST record essentially.. (it's an internal incrementer) – Allan Bowe Feb 20 '14 at 08:09