EXPORT Procedure

Example 1: Exporting to a Delimited External Data Source

Features:
PROC EXPORT statement options:
DATA=
DBMS=
OUTFILE=
REPLACE
DELIMITER=

Details

This example exports the SASHELP.CLASS data set to a delimited external file, and the PROC PRINT of this example is shown below. PROC PRINT of SASHELP.CLASS
Note that the filename does not contain an extension. DBMS=DLM specifies that the output file is a delimited file. The DELIMITER option specifies that an & (ampersand) will delimit data fields in the output file.

Program

proc export data=sashelp.class
   outfile="c:\myfiles\class"
   dbms=dlm;
   delimiter='&';
 run;

The SAS Log

The SAS log displays this information about the successful export, including the generated SAS DATA step.
1    proc export data=sashelp.class outfile="c:\myfiles\class" dbms=dlm;
1  !                                                                     delimiter='&'; run;

2     /**********************************************************************
3     *   PRODUCT:   SAS
4     *   VERSION:   9.3
5     *   CREATOR:   External File Interface
6     *   DATE:      31JAN11
7     *   DESC:      Generated SAS Datastep Code
8     *   TEMPLATE SOURCE:  (None Specified.)
9     ***********************************************************************/
10       data _null_;
11       %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
12       %let _EFIREC_ = 0;     /* clear export record count macro variable */
13       file 'c:\myfiles\class' delimiter='&' DSD DROPOVER lrecl=32767;
14       if _n_ = 1 then        /* write column names or labels */
15        do;
16          put
17             "Name"
18          '&'
19             "Sex"
20          '&'
21             "Age"
22          '&'
23             "Height"
24          '&'
25             "Weight"
26          ;
27        end;
28      set  SASHELP.CLASS   end=EFIEOD;
29          format Name $8. ;
30          format Sex $1. ;
31          format Age best12. ;
32          format Height best12. ;
33          format Weight best12. ;
34        do;
35          EFIOUT + 1;
36          put Name $ @;
37          put Sex $ @;
38          put Age @;
39          put Height @;
40          put Weight ;
41          ;
42        end;
43       if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
44       if EFIEOD then call symputx('_EFIREC_',EFIOUT);
45       run;

NOTE: The file 'c:\myfiles\class' is:
      Filename=c:\myfiles\class,
      RECFM=V,LRECL=32767,File Size (bytes)=0,
      Last Modified=31Jan2011:09:37:14,
      Create Time=31Jan2011:09:37:14

NOTE: 20 records were written to the file 'c:\myfiles\class'.
      The minimum record length was 17.
      The maximum record length was 26.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.91 seconds
      cpu time            0.04 seconds

19 records created in c:\myfiles\class from SASHELP.CLASS.

NOTE: "c:\myfiles\class" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           9.07 seconds
      cpu time            0.15 seconds

Output

The EXPORT procedure produces this external file:
External File
     Name&Sex&Age&Height&Weight     
     Alfred&M&14&69&112.5           
     Alice&F&13&56.5&84             
     Barbara&F&13&65.3&98           
     Carol&F&14&62.8&102.5          
     Henry&M&14&63.5&102.5          
     James&M&12&57.3&83             
     Jane&F&12&59.8&84.5            
     Janet&F&15&62.5&112.5          
     Jeffrey&M&13&62.5&84           
     John&M&12&59&99.5              
     Joyce&F&11&51.3&50.5           
     Judy&F&14&64.3&90              
     Louise&F&12&56.3&77            
     Mary&F&15&66.5&112             
     Philip&M&16&72&150             
     Robert&M&12&64.8&128           
     Ronald&M&15&67&133             
     Thomas&M&11&57.5&85            
     William&M&15&66.5&112