I need to append data to an external file which has a "trailer record". That means that what I want to "append" really needs to be inserted just before that record.
It's not HTML - but imagine if you needed to update an HTML file by inserting records prior to the </BODY> tag. It's a similar concept.
What I've come up with so far is kludgy:
1. Using DATA_NULL_, INFILE referencing the original, and FILE referencing a temporary file, copy all of the records except the trailer to a temporary file.
2. Using DATA_NULL_ and FILE referencing the temporary file with MOD, write the new records and then a trailer record
3. Using DATA _NULL_, INFILE referencing the temporary file and FILE referencing the original, copy all of the (updated) records from temporary to original
There's got to be a better way? And hopefully without risk of losing the records (although I will build in a backup)
Environment note: this is a text-type file within a Unix directory on a z/OS system.
Thanks for any help.
Hi,
What about:
1. Read original file into a SAS data set
2. Use set statement with end= option to write the data to the original file inserting the new records when the end= variable is 1, followed by the trailer.
Regards,
Amir.
Hi,
Actually, you should be able to just do it in one data step by reading the external file with the end= option writing out to the same external file. When the end= variable is 1 write the extra records followed by the trailer.
Regards,
Amir.
Hi,
An untested template example of my last suggestion:
data _null_;
file 'your-file-name';
infile 'your-file-name' end=lastrec;
input;
if lastrec then
do;
put 'new-rec-1';
put 'new-rec-2';
put 'new-rec-3';
end;
put _infile_;
run;
Regards,
Amir.
Thanks, your last example works
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.