Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Exporting

I have discussed how to import data into SAS from SPSS and Excel files, but what about when a user wishes to get the data out of SAS into another file format.  Exporting data is one of those times I really love SAS and the tools/wizards they provide.   Let’s start with the SAS Export Wizard.

The Export wizard:
                File -> Export Data…
Here you can see the Export Wizard is open and ready for you to select the file.  In the Library drop down menu, you simply select the library location, and the “member” is the file name.  In this example I would be exporting the SAS dataset “DATA” from the “WORK” library.
One thing you may quickly notice is the extensive list of file formats available to you by SAS.  A few include:  Excel, comma/tab delimited, JMP, SPSS, ect.  That is right SPSS!  I find it interesting that SAS will let users export straight into SPSS, and it works, but you can’t export an SPSS file into SAS without issues.
The final step after selecting the file format is to find the final folder destination of the data.  Once the destination is selected, you will assign a table name and hit FINISH, which will complete your export.
Simple, right? 
*************************************************************************************            
Option 2.  SAS Macro
When explaining how to import Excel files, I discussed the positives and negatives of using these macros for importing/exporting.  The only reason I use these macros is when importing the data, making quick changes, and exporting the data.  I won’t utilize this macro for my day to day exporting, but if I’m making summary variables or mean/mode/median imputations, this is the easiest way.
%macro expo (data=);
PROC EXPORT DATA= WORK.data
            OUTFILE= "C:\folder\datasets\Updated\&data"
            DBMS=EXCEL LABEL REPLACE;
     NEWFILE=YES;
RUN;
%mend;

*The first line creates a macro called “expo” where we are going to use the macro to define “data”.
The macro utilizes PROC EXPORT and states the data is in the work library and is called “data”.  Second note, I created a new file folder called “Updated”, so the data didn’t just overwrite the old data in the folder from where you imported the data.
DBMS=Excel, tells SAS it will be exporting the data as an Excel file with the labels printed instead of the names. ;

%mend;
*closes the macro.;
*The final step is calling the macro;

%expo(data=file);
This statement exports the SAS dataset as “file” into the folder on your drive specified in the macro statement.
These are just two of the forms of exporting data I use most often, but again, there are many ways to export. 
Cheers!


This post first appeared on SAS Beginner's Guide-Tips, Help And Statistics, please read the originial post: here

Share the post

Exporting

×

Subscribe to Sas Beginner's Guide-tips, Help And Statistics

Get updates delivered right to your inbox!

Thank you for your subscription

×