05-12-2014 12:11 PM
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.
05-12-2014 12:53 PM
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.
05-12-2014 12:57 PM
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.
05-12-2014 01:03 PM
An untested template example of my last suggestion:
infile 'your-file-name' end=lastrec;
if lastrec then