Sample 40191: Close a Microsoft Word document from within SAS
When creating RTF or Microsoft Word documents using ODS, you must close the file before you can run SAS code again that references the same filename. Otherwise, a "file in use" error is generated.
You can close Microsoft Word from within SAS using Dynamic Data Exchange (DDE). This is useful during the development stage of writing a SAS program that creates an RTF file. Typically in the development process, you submit a program several times. The RTF file needs to be closed each time. DDE enables you to make requests to the application using a FILE statement in the DATA step.
Dynamic Data Exchange (DDE) is a method of dynamically exchanging information between Windows applications. DDE uses a client/server relationship to enable a client application to request information from a server application. SAS is always the client. In this role, SAS requests data from server applications, sends data to server applications, or sends commands to server applications.
The sample code on the Full Code tab provides an illustration.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Dynamic Data Exchange (DDE) is a method of dynamically exchanging information between Windows applications. DDE uses a client/server relationship to enable a client application to request information from a server application. SAS is always the client. In this role, SAS requests data from server applications, sends data to server applications, or sends commands to server applications.
You can use DDE with the DATA step, the SAS macro facility, SAS/AF applications, or any other portion of SAS that requests and generates data. DDE has many potential uses, one of which is to acquire data from a Windows spreadsheet or database application.
This program closes Microsoft Word. This is useful when you are in the development stages of writing a program that creates an RTF file.
/* Use DDE to make the request to Microsoft Word */
filename word dde 'winword|system';
data _null_;
file word;
/* The following PUT statements execute Microsoft Word commands */
put '[FileClose 2]';
put '[FileExit 2]';
run;
/* Create a sample table routing to RTF using ODS */
ods rtf file="myfile.rtf";
proc tabulate data=sashelp.class;
class age sex;
table age,sex;
run;
ods rtf close;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
When creating RTF or Microsoft Word documents using ODS, you must close the file before you can run SAS code again that references the same filename. Otherwise, a "file in use" error is generated.
Date Modified: | 2011-09-28 11:31:25 |
Date Created: | 2010-07-02 10:29:14 |
Operating System and Release Information
SAS System | Base SAS | Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
Microsoft® Windows® for x64 | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
Microsoft Windows XP Professional | 9.2 TS1M0 | |
Windows Vista | 9.2 TS1M0 | |
Windows Vista for x64 | 9.2 TS1M0 | |