SAS Office Analytics, SAS Add-In for Microsoft Office, and other integrations

Reading RTF files in SAS dataset

Reply
Contributor
Posts: 65

Reading RTF files in SAS dataset

I have been doing some research on how to read a RTF file into a SAS dataset and haven't found much at all. Does anyone have any advise on reading in RTF files?

Thanks
Super Contributor
Super Contributor
Posts: 3,174

Re: Reading RTF files in SAS dataset

The SAS support http://support.sas.com/ website has a few SUGI/SGF conference papers and technical references on the topic - it will be a matter of user-coded DATA step processing to parse/read the RTF data lines, interpret the commands/data-strings and generate your desired SAS dataset and variables.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic/post:

read rtf file site:sas.com

read external data site:sas.com

data step programming introduction site:sas.com Message was edited by: sbb
SAS Super FREQ
Posts: 8,820

Re: Reading RTF files in SAS dataset

Hi:
In addition to Scott's suggestion, I have had students do the following:
1) open the RTF file with Word
2) highlight and cut/copy the table in Word
3) paste the table into Excel
4) save the Excel file to an XLS file
5) read the Excel file with PROC IMPORT or the Libname Engine

I would imagine that the process can be automated with Office macros or VB scripts. Depending on the volume of RTF files to be read, if you have a lot of RTF files, then you might want to invest the energy in the DATA step approach.

cynthia
Super User
Posts: 9,878

Re: Reading RTF files in SAS dataset

Hahahaha.....
That is a good idea.I learned it .
Occasional Contributor
Posts: 14

Re: Reading RTF files in SAS dataset

Hi Cynthia,

Thank you for all your insightful postings. I guess that you may be working for SAS.

Is it possible for SAS to come up with a %rtfToSAS so we can just import the rtf tables back into SAS data sets?

Regards,
Super Contributor
Super Contributor
Posts: 3,174

Re: Reading RTF files in SAS dataset

Not sure it would make sense for SAS Institute - have you considered the number of standards/versions?

http://en.wikipedia.org/wiki/Rich_Text_Format

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,820

Re: Reading RTF files in SAS dataset

Hi:
I agree with Scott -- it doesn't make sense to me for an "RTF2SAS" routine. For one thing, an RTF file is a document -- with TITLES and FOOTNOTES and procedure titles and possibly a TABLE of contents. What if there is a table that spans pages? What if there is a table with ancillary text as a caption??? What if there are 10 footnotes with information about outliers??? What if there is one table of people's names and ages and another table of people's names and addresses -- would those be 2 separate datasets?? I don't think there's a way to write a generic program to parse the RTF description of a document and turn any tables found in that document into a SAS dataset(s).

I know that several folks have worked on parsing RTF and Word XML files. I believe there was a reference to this paper:
http://www.pharmasug.org/cd/papers/TT/TT13.pdf

That might be one place to start if you are intent on having such a conversion available.

cynthia
N/A
Posts: 0

Re: Reading RTF files in SAS dataset

Hi,

I have written a paper to convert .rtf files into sas datasets.

This paper will be presented in Pharmasug2010 next week.

Please check the online proceedings of PharmaSUG2010 in a week or two.

Regards
Ask a Question
Discussion stats
  • 7 replies
  • 2248 views
  • 0 likes
  • 6 in conversation