|
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
---------------------------------
|