01-04-2018 04:04 AM - edited 01-04-2018 04:04 AM
I have one RTF file which has some data in it, Lets assume the file name is Test1.rtf.
Now through Proc Report I have to append data from a new dataset to the existing Test1.rtf.
please help me how can we do this. It should not overwrite the existing file.
01-04-2018 04:22 AM
RTF is a variant of "tagged" data, but different than HTML. So the existing file has a defined "end", and appending won't work. The word processor would stop reading as soon as it reaches the "end" mark of the initial file.
You can test this by opening a .rtf file with a standard text editor (notepad++), and appending all its contents a second time. When you open this with a word processor (I dit it with LibreOffice), you will only see the contents of the initial file. The "add-on" data is discarded.
You have two options:
#1: take the original data from which the RTF was created, append your current data, and create the file anew
#2: read the RTF as pure text, up to the "end" tag, and insert your new data (correctly tagged according to RTF norm), and add the end tag
#1 is to be preferred, of course.
01-04-2018 04:24 AM
That will prove to be very difficult. RTF is a tagset based text file. You can open it in Notepad or a text editor and see, there are numerous tags which tell the rendering program (Word for instance) how to use and display the data. So first off you will need to know what all the tags are and how to work with them. Then you can open the text file in a datastep, read it line by line until the point you want to insert, then go ahead and start writing out the data with all the associated tabs.
I would really recommend you don't though as its an inordinate amount of work for little to no gain. Is this a repeatable thing? If so then get the datasets underlying the RTF, this is the best solution all round as you have the data and can do other things with it, you can also append your data and recreate the RTF.
If it is a one off, then the simplest method would be to create and RTF with your data, then open the original in Word, and your one, copy and paste all your RTF output into the other in Word, then use Word to SaveAs RTF. The output file will be slightly different from the SAS generated tagset, but will include both files.
The third option of doing it all yourself, well, good luck with that...
01-04-2018 10:17 PM
If you want to append output from a SAS program to an already existing .rft then that's going to be very difficult and not worth trying.
IF this is about creating a .rft with output from multiple steps out of the SAME program then this can be done. What's the case you're dealing with?