Prepared by Destiny Corporation: Reading and Writing Data From Microsoft Excel/Word Using DDE
Prepared by Destiny Corporation: Reading and Writing Data From Microsoft Excel/Word Using DDE
Prepared by Destiny Corporation: Reading and Writing Data From Microsoft Excel/Word Using DDE
The DDE Triplet is then incorporated into a Filename With Excel running and the above spreadsheet
statement of the following form: open, a simple Data Step can be written to read the
above data into a SAS Data Set.
FILENAME fileref DDE 'DDE-
'DDE-Triplet' | The DDE Triplet components for the above example
'CLIPBOARD' <DDE-
<DDE-Options>; are as follows:
where: Name of Executable File: EXCEL
fileref is a valid fileref
Full Path and Name of spreadsheet file:
C:\COURSES\DATA\CLIN.XLS
Location of data (Row and Column coordinates): DDE Triplet points at a different range of cells in the
R4C1:R17C8 spreadsheet.
Note how the two sets of coordinates that define the A null data step is used to read the data set
range of data are separated by a colon. containing the statistics and ‘Put’ statements write
out the values of selected variables to the Excel
The SAS statements required to read the data into a spreadsheet. This is no different to writing out data
SAS data set are as follows: to a text file.
X ‘C:\EXCEL\EXCEL’;
Note that the only change to the Filename statement
compared with the previous example, is that the
DATA _NULL_;
T=SLEEP(5);
RUN;
DATA _NULL_;
FILE CMDS;
PUT ‘[FILE- To create a bookmark within a Word document,
OPEN(“C:\COURSES\DATA\CLIN.XLS”)]’;
highlight the text which you want to use as a
bookmark, then select Edit and Bookmark from the
pull down menu:
RUN;
Enter a name for the bookmark
Example of invoking and issuing commands to
Excel
The example program does the following:
1. Invokes Excel.
2. Opens a Spreadsheet.
3. Reads spreadsheet data into a SAS data set.
4. Closes the Spreadsheet.
5. Closes Excel.
The components of the DDE Triplet for the above
example are as follows:
X ‘C:\WINWORD\WINWORD’;
DATA _NULL_;
T=SLEEP(5);
RUN;
1. Invoke Excel.
2. Open the spreadsheet file that you have created
for this exercise.
3. Write out values of Demographic Data Set
variables to the Excel spreadsheet.
4. Save the spreadsheet.
5. Close the spreadsheet file.
6. Close Excel.
Prepared by: