Database Reference
In-Depth Information
Figure 11.6.6: SAS Code to Process the “Hello World” Project with a Closed Excel File as
Input.
OPTIONS NOXWAIT NOXSYNC;
/* Use to X command to start Excel 2013*/
%let Excel_path =
'C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE';
* no spaces in unquoted file path or name;
%let Excel_file = C:\Excel_Files\Book2.xlsx;
X "&Excel_Path. /x &excel_file.";
DATA _NULL_;
x = sleep( 10 ); * Allow enough seconds for Excel to open;
RUN ;
FILENAME ddewrite DDE 'excel| C:\Excel_Files\[Book2.xlsx]Sheet1!r1c1:r1c2';
DATA OUT;
FILE ddewrite;
x='Hello World';
PUT x;
RUN;
Once again, the simple act of finding the words “Hello” and “World” complete this exercise. Note here that
each word is in a separate cell of the Excel worksheet, just like they were in Figure 11.6.4. Also, this
example opened Excel before writing the output text, and did not close Excel when finished. Figure 11.6.7
shows the results.
Figure 11.6.7: Excel File with “Hello” “World” in Cells R1C1 and R1C2 (A1:B1).
Example 11.6.3 The Hello World Project Using NOTAB and LRECL= Options
This example is also very similar to the first example except that it starts with the Excel file closed. The
SAS “X” command is used to issue an operating system command to start the Excel application before
running the DDE commands from SAS. Some of the newer versions of Microsoft Excel take several
seconds to open and activate the add-ins that are installed. The number and type of add-ins may vary for
each computer installed in your area. Since SAS and Excel must both be running at the same time, it is
important to wait long enough for Excel to be fully active before issuing a DDE command.
 
Search WWH ::




Custom Search