axio research

31
Axio Research Generation of Appended Reports Architecture and Automation Bill Coar ([email protected])

Upload: andie

Post on 12-Feb-2016

23 views

Category:

Documents


1 download

DESCRIPTION

Axio Research. Generation of Appended Reports Architecture and Automation Bill Coar ([email protected]). Generation of Appended Reports. SAS. Existing RTF reports. ODBC. Automation Using Existing Architecture. Program Tracker. MS Word. Appended report with Table of Contents. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Axio  Research

Axio Research

Generation of Appended Reports

Architecture and Automation

Bill Coar([email protected])

Page 2: Axio  Research

Automation Using Existing Architecture

Generation of Appended ReportsSAS

Sweet SAS Code

MS Word

Existing RTF

reports

Appended report

with Table of Contents

ODBC

DDE

Program Tracker

Page 3: Axio  Research

The Goals

• Develop a tool to append existing RTF files into a single report that contains a hyperlinked (pseudo) table of contents– Assume common page layout for each RTF

• Use existing infrastructure• Independent of user• (Easily) automated

Page 4: Axio  Research

The motivation for using SAS

• Base knowledge of SAS > Word• Can use existing files and directory structures• Can be automated via SAS macros • Made available to all SAS users

Did you ever try to append RTF files using Word?

Page 5: Axio  Research

The SchematicSweet SAS Code

MS Word

Existing RTF

reportsAppended report

with Table of Contents

SAS

ODBC

Program Tracker

DDE

Page 6: Axio  Research

The Idea

• Read in a list of RTF files from the program tracker

• Update the dataset– Bookmarks– RTF code

• ODS to RTF for Table of Contents• DDE to communicate with Word

– Open and Append each RTF– Final updating and saving

Page 7: Axio  Research

The Program Tracker• One record per output

– Necessary for Table of Contents– Not the same as one program per output

• Columns for:– Output file name– TLF number for sorting– TLF text to be displayed in hyperlink– If appropriate, sub-setting columns

• Example

Page 8: Axio  Research

Reading the Program Tracker

• Establish a link to the program tracker– Do not need to create an ODBC connection

outside of SAS

• Side notes:– File must not be in use by others– Some common format is desirable to standardize

across projects

libname myxls odbc required="Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};dbq=&DIRPATH.\Sample Program Tracker.xlsx";

Page 9: Axio  Research

Reading the Program Tracker

DATA X;set myxls.'TFL Timelines$'n;

* Insert some sweet SAS code for displaying RTF codes (hyperlinks and bookmarks) as well as sorting variables.

Run;

Page 10: Axio  Research

The Idea

• Read in a list of RTF files from the program tracker

• Update the dataset– Bookmarks– RTF code

• ODS to RTF for Table of Contents• DDE to communicate with Word

– Open and Append each RTF– Final updating and saving

Page 11: Axio  Research

Update the dataset

• Create a bookmark for each file – To be inserted just before the RTF is appended

• Create sorting variables based on TLF types and numbers– Many alternatives for sorting

• Two columns for display– RTF code for hyperlink– RTF code for cross-reference to bookmark for

page numbering

Page 12: Axio  Research

Update the datasetDATA X;

set myxls.'TFL Timelines$'n;length toc $150 pageno $100 bnum $5;

bnum="BN"||left(put(_n_,z3.));

toc='{\field {\*\fldinst HYPERLINK \\l "'||bnum||'" }{\fldrslt { \cs15\cf2 '||trim(ttl)||' }}}';

pageno='{\field {\*\fldinst PAGEREF '||bnum||' \\h }}';

* Insert code to create some sorting variables.Run;

Desired Text for Titles in Hyperlinks

with TOC

Page 13: Axio  Research

Consider Defensive Programming

• Verify the output file actually exists– Output warnings in log file– Only keep records where the files exist

Data errata;set Xlength opath $200;opath="&Dirpath\Out\"||file_name;fe=fileexist(opath);if fe=0;put "WARN""ING - Some output files do not exist. Please

verify";put opath=;

Run;

Specify full directory path

where RTF files exist

Page 14: Axio  Research

The Idea

• Read in a list of RTF files from the program tracker

• Update the dataset– Bookmarks– RTF code

• ODS to RTF for Table of Contents• DDE to communicate with Word

– Open and Append each RTF– Final updating and saving

Page 15: Axio  Research

ODS to RTF

• Proc report using ODS to RTF– Eventually be the first page of the report– Contains the (eventual) table of contents

• Consider standard titles/footnotes• Turn the results viewer off• Close the RTF destination• Decide on orientation

Page 16: Axio  Research

ODS to RTF

• The RTF created:– Should see the hyperlinks, but not page numbers

since the bookmarks needed for the referencing do not yet exist

– Is the starting point to begin appending the individual reports

• Example

Page 17: Axio  Research

The Idea

• Read in a list of RTF files from the program tracker

• Update the dataset– Bookmarks– RTF code

• ODS to RTF for Table of Contents• DDE to communicate with Word

– Open and Append each RTF– Final updating and saving

Page 18: Axio  Research

DDE Workhorse

• Open Word (from within SAS)• Establish DDE Link• Dynamic Data Exchange (DDE)

– SAS to communicate with MS Word through an established link

– Use WordBasic commands to tell Word what to do

Page 19: Axio  Research

Open Word and Establish DDE Link

data _null_;length fname $ 8;fname='tempfile';rc=filename(fname,'C:\Progra~1\Micros~1\Office12\

WINWORD.EXE');if (rc=0) and (fexist(fname)) then do;

call system('start C:\Progra~1\Micros~1\Office12\WINWORD.EXE');

end;rc=filename(fname);t=sleep(1);

run;filename testit dde 'winword|system';

Page 20: Axio  Research

DDE Workhorse• Open the RTF that contains the TOC• (Setup page layout for remaining (imported)

RTFs)• For each report

– Insert a bookmark– Insert the file– Insert section break

• Save the document as a DOC file– Initial save for establishing page numbers

Page 21: Axio  Research

DDE Workhorse

• Issuing WordBasic commands– Within a data step– May/may not need information from input dataset

• Create variables that consist of WordBasic commands

• Put the commands to the filename that defines the DDE link

Page 22: Axio  Research

Example: Open the RTF file with initial table of contents

data null;file testit;length cmd $200;* Open the initial RTF that contains the table of contents.;cmd='[FileOpen.Name = "'||"&dirPath.\Out\filename.RTF"||'"]';put cmd;* Go to the end of the document to begin inserting RTF files.;cmd='[EndofDocument]';put cmd;* Insert a new section for purposes of titles and footnotes.;cmd='[InsertSectionBreak]';put cmd;

run;

Page 23: Axio  Research

DDE Workhorse• Setup page layout for remaining (imported) RTFs

– cmd='[FilePageSetup .TopMargin="1.5 in" .BottomMargin=".5 in" .LeftMargin=".7 in" .RightMargin=".7 in"]';

• For each report (use the toc dataset)– Insert a bookmark

• cmd='[SetStartOfBookmark "\Line" ,"'||bnum||'"]';– Insert the file

• cmd='[InsertFile .Name="'||trim(file_name)||'" .Range="" .Link=0 .ConfirmConversions=0]';

– Insert a section breakVariables in the input dataset used for the proc report/table of contents

Page 24: Axio  Research

DDE Workhorse

• Save the document as a DOC file– Initial save for establishing page numbers

• cmd='[FileSaveAs.Name =' ||'"'|| filename ||'"' || ', .Format=0]';

• Update the ToC– Go to beginning

• cmd='[StartofDocument]';– Select the first table

• cmd='[TableSelectTable]';– Update fields

• cmd='[UpdateFields]';

Page 25: Axio  Research

DDE Workhorse• Re-save the Word document

– cmd='[FileSave]';• Close the document

– cmd='[FileClose]';• Close Word

– cmd='[FileExit]';• Example

Page 26: Axio  Research

Some Pros/Cons• Pros:

– (In theory) Can be standardized to work for any project if trackers are consistent• Eliminate the need for project specific Word macros

– Allows for re-number of tables w/o change macro code

– Less human intervention– Can be modified to allow for multiple reports per

RTF file (bookmarks created by SAS)– Can update page numbers if post processing

• Print preview, or Cntrl-A then F9

Page 27: Axio  Research

Some Pros/Cons• Cons:

– Code can be intimidating (though we are still <1KLOC)

– Windows issues if mistakes are made• Application hangs…

– Possible issues with DDE• Tmpdde in word macros• Corrupt windows profile

Page 28: Axio  Research

Some Pros/Cons• Cons:

– Not sure if WordBasic is supported any more• Excel Help file for word basic commands

– http://www.microsoft.com/downloads/en/details.aspx?familyid=1a24b2a7-31ae-4b7c-a377-45a8e2c70ab2&displaylang=en

• Issues with Windows 7 and Vista reading Windows Help files

– http://support.microsoft.com/kb/917607

Page 29: Axio  Research

Final Remarks• It seems to work so far

– Used successfully for inserting up to 100 RTF files (>1000 pages)

• Many of the Word Basic commands are straightforward– Commands executed interactively to better

understand functionality• Links maintained when converted to PDF with

Adobe writer– Not sure about free PDF writers

Page 30: Axio  Research

References

• Shannon, D. “To ODS RTF and Beyond”, SUGI 27, Paper 1-27

• Osowski, S., Fritchey, T. “Hyperlinks and Bookmarks with ODS RTF”, Pharmasug 2006, Paper TT21

• Tong, C. “ODS RTF: Practical Tips”, NESUG 16, Paper AT007

• Gilmore, J. “Using Dynamic Data Exchange with Microsoft Word”, SUGI 22, Paper 308

Page 31: Axio  Research

Axio Research

Questions?