Chapter Contents

Previous

Next
The IMPORT Procedure

Example 1: Importing a Delimited External File


Procedure features:
PROC IMPORT statement arguments:
DATAFILE=
DBMS=
OUT=
REPLACE
Data source statements:
DELIMITER=
GETNAMES=
Other features:
PRINT procedure

This example imports the following delimited external file and creates a temporary SAS data set named WORK.MYDATA.
Region&State&Month&Expenses&Revenue
Southern&GA&JAN97&2000&8000
Southern&GA&FEB97&1200&6000
Southern&FL&FEB97&8500&11000
Northern&NY&FEB97&3000&4000
Northern&NY&MAR97&6000&5000
Southern&FL&MAR97&9800&13500
Northern&MA&MAR97&1500&1000


Program
 Note about code
proc import datafile="/myfiles/mydata"
 Note about code
            out=mydata
 Note about code
            dbms=dlm
 Note about code
            replace;
 Note about code
   delimiter='&';
 Note about code
   getnames=yes;
run;
 Note about code
options nodate ps=60 ls=80;

proc print data=mydata;
run;


SAS Log
The SAS log displays information about the successful import. For this example, PROC IMPORT generates a SAS DATA step, as shown in the partial log that follows.

 8    /**********************************************************************
 9    *   PRODUCT:   SAS
10    *   VERSION:   8.00
11    *   CREATOR:   External File Interface - Version 1.1
12    *   DATE:      01MAR1999
13    *   DESC:      Generated SAS Datastep Code
14    *   TEMPLATE SOURCE:  (None Specified.)
15    ***********************************************************************/
16       data WORK.MYDATA                                 ;
17       %let _EFIERR_ = 0;     /* clear ERROR detection macro variable */
18       infile '/myfiles/mydata' delimiter = '&' MISSOVER
18 !  DSD lrecl=32767 firstobs=2 ;
19          format Region $8. ;
20          format State $2. ;
21          format Month $5. ;
22          format Expenses best12. ;
23          format Revenue best12. ;
24          informat Region $8. ;
25          informat State $2. ;
26          informat Month $5. ;
27          informat Expenses best32. ;
28          informat Revenue best32. ;
29       input
30                   Region $
31                   State $
32                   Month $
33                   Expenses
34                   Revenue
35       ;
36       If _ERROR_ then        /* ERROR detection */
37          call symput('_EFIERR_',1);
38       run;
NOTE: Numeric values have been converted to character 
      values at the places given by: (Line):(Column).
      86:31   
NOTE: 7 records were read from the infile 
      '/myfiles/mydata'.
      The minimum record length was 27.
      The maximum record length was 28.
NOTE: The data set WORK.MYDATA has 7 observations and 5 variables.
NOTE: DATA statement used:
      real time           7.91 seconds
      cpu time            0.97 seconds
      
  
  
-42 rows created in WORK.MYDATA                               from 
/myfiles/mydata. 
NOTE: WORK.MYDATA was successfully created.
NOTE: PROCEDURE IMPORT used:
      real time           1:58.92
      cpu time            11.03 seconds
      


Output
This output lists the output data set, MYDATA, created by PROC IMPORT from the delimited external file. [HTML Output]  [Listing Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.