Friday, March 18, 2016

Hack 2.10 Starting Windows® Programs from Within a SAS Program

SAS Programming Professionals,

Did you know that you can open other Windows programs from within a SAS program?

You might decide that it would be convenient to open Word, Excel, Windows Explorer, Internet Explorer, or possibly PowerPoint at some time during the execution of a SAS program.  If so, it can be done programmatically using the SYSTEM function.

In this example, we create a CSV file and then open Excel to QC the contents of that file:

ods results off;

ods csv file="c:\temp\classlist.csv";

proc print noobs data=sashelp.class;
run;

ods csv close;

data _null_;
   rc=system("start excel c:\temp\classlist.csv");
run;

You can see from the code that we are using the Output Delivery System to create a CSV file named classlist.csv.  The DATA _NULL_ step uses the SYSTEM command to “START” excel and open classlist.csv.

Here is an example of creating an RTF file and then launching Word to open that file:


options nodate nonumber;

ods results off;
ods rtf file="c:\temp\classlist.rtf";

proc print noobs data=sashelp.class;
title1 "Mrs. Dob's 7th Grade Class Roster";
run;

ods rtf close;


data _null_;
   rc=system("start winword c:\temp\classlist.rtf");
run;

Pretty neat, eh?  Don’t take my word for it; enter these examples into a SAS Display Manager session and take them for a test drive.

You can also use the SYSTEM command in open code via SAS Macro code as in this example that launches my favorite web site:


%let rc=%sysfunc(system(start iexplore http://support.sas.com/index.html));

I would bet that you can find dozens of uses for opening Windows programs with the SYSTEM function in your own SAS programs!

Best of luck in all of your SAS endeavors!

----MMMMIIIIKKKKEEEE

(aka Michael A. Raithel)

Excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers


I plan to post each and every one of the hacks in the book to social media on a weekly basis.  Please pass them along to colleagues who you know would benefit.