LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 12 Dec 2001 16:06:52 -0000
Reply-To:   "Vyverman, Koen" <koen.vyverman@FID-INTL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Vyverman, Koen" <koen.vyverman@FID-INTL.COM>
Subject:   Re: converting RTF to ASCII
Content-Type:   text/plain; charset="iso-8859-1"

Robert,

> Does anybody have some SAS code that will strip the tags from > an RTF file so > that it becomes a plain text file?

Assuming you're on Windoze ...

I tend to let M$ Word do the work, rather than going into an RTF file myself and trying to make sense of all those convolu- ted, nested, and redundantly repeating tags. Give the following a try. Works here on WinNT4.0 with SAS8.2 and Office97. Path- and filenames are treated separately, a matter of personal preference I guess ... Oh yes, a certain measure of DDE is used.

%macro rtf2txt( filepath=, filename=, savepath=, savename= );

options noxsync noxwait; filename sas2word dde 'winword|system' lrecl=1024; data _null_; length fid rc start stop time 8; fid=fopen('sas2word','s'); if (fid le 0) then do; rc=system('start winword'); start=datetime(); stop=start+10; do while (fid le 0); fid=fopen('sas2word','s'); time=datetime(); if (time ge stop) then fid=1; end; end; rc=fclose(fid); run;

data _null_; length ddecmd $ 512; file sas2word; put '[appminimize]'; ddecmd='[chdefaultdir "'||"&filepath"||'",0]'; put ddecmd; ddecmd='[fileopen.name="'||"&filename"||'"]'; put ddecmd; ddecmd='[chdefaultdir "'||"&savepath"||'",0]'; put ddecmd; ddecmd='[filesaveas.name="'||"&savename"||'",.format=2]'; put ddecmd; put '[fileclose]'; put '[appclose]'; run;

filename sas2word clear;

%mend rtf2txt;

%rtf2txt( filepath=%str(c:\temp), filename=%str(Sample RTF File.rtf), savepath=%str(c:\temp), savename=%str(Sample RTF File.txt) );

Of course, whether this will suit you or not depends on what kind of special characters appear in your RTF file. You know, some stuff invariably gets lost in translation to TXT.

For example, if your RTF contains the greek alpha character, in, say the Symbol font, it will get translated into a simple 'a'. If you care about such subtleties, I'd suggest pre-processing your RTF file after opening it in Word, using *gasp* more DDE to automate the use of the Find and Replace function to translate characters into menmonics. You might e.g. replace every greek alpha by a string '<alpha>' which will be conserved in your flatfile.

Hope this helps, Koen.

--------------------------------- Koen Vyverman Database Marketing Manager Fidelity Investments - Luxembourg ---------------------------------


Back to: Top of message | Previous page | Main SAS-L page