Friday, May 6, 2016

Hack 3.5 Creating a PROC EXPORT or PROC IMPORT Template Program

SAS Programming Professionals,

Did you know that you don't have to memorize the exact syntax and all of the options of PROC EXPORT or PROC IMPORT, or go fumbling for the documentation every time you need to use them? 

Instead, create a PROC EXPORT template and a PROC IMPORT template for yourself using the wizards in SAS Display Manager.  Then, copy either template into your programs and modify the code to suit the particular needs of the export or import situation at hand.

In SAS Display Manager, select: <File>, then <Export Data>.  Choose the SASHELP.CLASS SAS data set just to have something to work with.  Then, go through all of the subsequent windows, choosing each and every one of the available options.  When you get to the window that states:

"The EXPORT wizard can create a file containing PROC EXPORT commands that can be used in SAS programs to export this data again.  If you want these statements to be generated, enter the filename where they should be saved."

…choose a directory and then a meaningful program name, such as "Export to Excel Template.sas".  When you click <Finish>, you will have a SAS program that looks something like this:

PROC EXPORT DATA= SASHELP.CLASS
     OUTFILE= "C:\Documents and Settings\RAITHEL_M\SAS Class.XLS"
     DBMS=EXCEL LABEL REPLACE;
     RANGE="SAS Class";
     NEWFILE=YES;
RUN;

You can reverse this process with the Import Data wizard to create a PROC IMPORT template.  Now how hard is that?  A little pre-planning now, may save you a lot of time later!

Best of luck in all 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.

No comments:

Post a Comment