Previous Page | Next Page

The EXPORT Procedure

Example 1: Exporting a Delimited External File


Procedure features:

The EXPORT procedure statement arguments:

DATA=

DBMS=

OUTFILE=

Data source statement:

DELIMITER=


This example exports the SAS data set SASHELP.CLASS to a delimited external file.

PROC PRINT of SASHELP.CLASS

                            The SAS System                                1

     Obs    Name        Sex             Age          Height          Weight

       1    Alfred       M               14              69           112.5
       2    Alice        F               13            56.5              84
       3    Barbara      F               13            65.3              98
       4    Carol        F               14            62.8           102.5
       5    Henry        M               14            63.5           102.5
       6    James        M               12            57.3              83
       7    Jane         F               12            59.8            84.5
       8    Janet        F               15            62.5           112.5
       9    Jeffrey      M               13            62.5              84
      10    John         M               12              59            99.5
      11    Joyce        F               11            51.3            50.5
      12    Judy         F               14            64.3              90
      13    Louise       F               12            56.3              77
      14    Mary         F               15            66.5             112
      15    Philip       M               16              72             150
      16    Robert       M               12            64.8             128
      17    Ronald       M               15              67             133
      18    Thomas       M               11            57.5              85
      19    William      M               15            66.5             112

Program

This example exports the SASHELP.CLASS data set and specifies the output filename. 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.

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


SAS Log

The SAS log displays this information about the successful export, including the generated SAS DATA step.

47    /**********************************************************************
48    *   PRODUCT:   SAS
49    *   VERSION:   9.00
50    *   CREATOR:   External File Interface
51    *   DATE:      07FEB02
52    *   DESC:      Generated SAS DATA step code
53    *   TEMPLATE SOURCE:  (None Specified.)
54    ***********************************************************************/
55       data _null_;
56       set  SASHELP.CLASS                                end=EFIEOD;
57       %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
58       %let _EFIREC_ = 0;     /* clear export record count macro variable */
59       file 'c:\myfiles\class' delimiter='&' DSD DROPOVER
59 ! lrecl=32767;
60          format Name $8. ;
61          format Sex $1. ;
62          format Age best12. ;
63          format Height best12. ;
64          format Weight best12. ;
65       if _n_ = 1 then        /* write column names */
66        do;
67          put
68          'Name'
69          '&'
70          'Sex'
71          '&'
72          'Age'
73          '&'
74          'Height'
75          '&'
76          'Weight'
77          ;
78        end;
79        do;
80          EFIOUT + 1;
81          put Name $ @;
82          put Sex $ @;
83          put Age @;
84          put Height @;
85          put Weight ;
86          ;
87        end;
88       if _ERROR_ then call symput('_EFIERR_',1);  /* set ERROR detection
88 ! macro variable */
89       If EFIEOD then
90          call symput('_EFIREC_',EFIOUT);
91       run;

NOTE: Numeric values have been converted to character
      values at the places given by: (Line):(Column).
      88:44   90:31
NOTE: The file 'c:\myfiles\class' is:
      Filename=c:\myfiles\class,
      RECFM=V,LRECL=32767

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.13 seconds
      cpu time            0.05 seconds


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


NOTE: c:\myfiles\class was successfully created.

Output: External File

The EXPORT procedure produces this 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

Previous Page | Next Page | Top of Page