Date: Wed, 17 Dec 2008 12:00:14 +0800
Reply-To: =?UTF-8?B?546L5Yab?= <wangjun.sh@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: =?UTF-8?B?546L5Yab?= <wangjun.sh@GMAIL.COM>
Subject: [Resolved]Re: How to delete level 2 toc entry for Table of
Contents in SAS v9.2
In-Reply-To: <9042fd940812161949j283385ffp732bd565d4e7e28b@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Dear all,
Finally I figured out a stupid way to achieve this. I use perl regular
expression to match the level 2 toc entry in the ods generated rtf
file, and then replace it with blank to remove it. Now it works fine.
If you have better ideas about how to remove this level 2 toc entry,
please also be so kind to tell us.
Part of the sas code below. temp dataset contains all rtf text.
data _null_;
file _fileout lrecl=2000;
set temp;
**** Remove the level 2 toc entry, for SAS v9.2 only;
if _N_ = 1 then do;
retain PerlExpression;
**** start with {\plain\tc\v\f1\fs22\b0\i0);
**** end with \tcf67 \tcl2 };
pattern =
"s/^({\\plain\\tc\\v\\f1\\fs22\\b0\\i0).*(\\tcf67 \\tcl2 })//";
PerlExpression = prxparse(pattern);
end;
if prxmatch(PerlExpression,string) then do;
call prxchange(PerlExpression,-1,string);
end;
len=length(string);
put string $varying2000. len;
run;
Best regards,
John Wang
On Mon, Dec 15, 2008 at 1:40 PM, 王军 <wangjun.sh@gmail.com> wrote:
>
> Dear All,
>
> I am starting to use SAS v9.2. But I find that the Table of Contents created in v9.2 are different than v9.1 There is an extra level 2 toc entry in the Table of Contents now.
>
> I know that I can use VBScript to delete those entries in word files. But I want to do it in SAS way. Anyone know how to remove the level 2 toc entry in SAS v9.2?
>
>
> 1. VBScript Code:
>
> ''''''''''''''''''''''''''''''
> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> Dim objWord
>
> Set objWord = CreateObject("Word.Application")
>
> objWord.Visible = TRUE
> objWord.Documents.Open(wordFile)
>
> ' Remove the level 2,3 toc entry
> Dim objSelection, wdfield
> Set objSelection = objWord.Selection
>
> For Each wdfield In objWord.ActiveDocument.Fields
> If InStr(wdfield.Code, "\f C \l 2") Or InStr(wdfield.Code, "\f C \l 3") Then
> wdfield.Delete
> End If
> Next
> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>
>
> 2. SAS code.
>
> *----------------------------------------------------------------------------*
> * prepare for dataset;
> *----------------------------------------------------------------------------*;
>
> data final;
> set sashelp.class
> sashelp.class
> sashelp.class
> sashelp.class
> sashelp.class
> sashelp.class
> sashelp.class
> ;
>
> pageno = ceil(_n_/20);
>
> proc sort; by pageno;
> run;
>
> *----------------------------------------------------------------------------*
> * Prepare for report;
> *----------------------------------------------------------------------------*;
> ods noresults;
> ods escapechar="~";
> options orientation=portrait number pageno=1;
> options topmargin=1in
> bottommargin=1in
> leftmargin=1.25in
> rightmargin=1in;
> ods listing close;
> ods proclabel "Hello, the world";
> ods rtf file="d:\test_toc.rtf" style=rtf
> contents toc_data bodytitle;
>
> proc report data=final nowindows missing contents=""
> style(report)={outputwidth=95%}
> ;
>
> column pageno Name Sex Age Height Weight;
>
> define pageno /group noprint order=data;
> define Name /display style(column)={cellwidth=10%};
> define Sex /display style(column)={cellwidth=10%};
> define Age /display style(column)={cellwidth=10%};
> define Height /display style(column)={cellwidth=10%};
> define Weight /display style(column)={cellwidth=10%};
>
> break after pageno /page;
>
> title1 "this is a test for TOC";
> run;
>
> ods rtf close;
> ods listing;
>
>
>
>
> Best regards,
> John Wang
|