specifies the complete path and filename or fileref for the input PC file, spreadsheet, or delimited external file. A fileref is a SAS name that is associated with the physical location of the output file. To assign a fileref, use the FILENAME statement.
Restrictions | The IMPORT procedure does not support device types or access methods for the FILENAME statement except for DISK. For example, the IMPORT procedure does not support the TEMP device type, which creates a temporary external file. |
The IMPORT procedure can import data only if SAS supports the data type. SAS supports numeric and character types of data but not (for example) binary objects. If the data that you want to import is a type that SAS does not support, the IMPORT procedure might not be able to import it correctly. In many cases, the procedure attempts to convert the data to the best of its ability. However, conversion is not possible for some types. | |
Interactions | By default, the IMPORT procedure reads delimited files as varying record-length files. If your external file has a fixed-length format, use the FILENAME statement prior to PROC IMPORT to specify the input filename using the RECFM=F and LRECL= options. |
When you use a fileref to specify a delimited file to import, the logical record length (LRECL) defaults to 256, unless you specify the LRECL= option in the FILENAME statement. The maximum LRECL value that the IMPORT procedure supports is 32,767. | |
For delimited files, the first 20 rows are scanned to determine the variable attributes. You can increase the number of rows that are scanned by using the GUESSINGROWS= statement. All values are read in as character strings. If a Date and Time format or a numeric informat can be applied to the data value, the type is declared as numeric. Otherwise, the type remains character. |
identifies the output SAS data set with either a one or two-level SAS name (library and member name). If the specified SAS data set does not exist, the IMPORT procedure creates it. If you specify a one-level name, by default the IMPORT procedure uses either the USER library (if assigned) or the WORK library (if USER is not assigned).
specifies the name of the input DBMS table. If the name does not include special characters (such as question marks), lowercase characters, or spaces, you can omit the quotation marks. Note that the DBMS table name might be case sensitive.
Requirement | When you import a DBMS table, you must specify the DBMS= option. |
specifies the type of data to import.
overwrites an existing SAS data set. If you omit REPLACE, the IMPORT procedure does not overwrite an existing data set.
specifies SAS data set options. For example, to assign a password to the resulting SAS data set, you can use the ALTER=, PW=, READ=, or WRITE= data set options. To import only data that meets a specified condition, you can use the WHERE= data set option.
Restriction | You cannot specify data set options when importing delimited, comma-separated, or tab-delimited external files. |
options validvarname=v7; /*#1*/ proc import datafile='C:UsersStudent1certoots.xlsx' /*#2*/ dbms=xlsx out=work.bootsales replace; sheet=boot; /*#3*/ getnames=yes; /*#4*/ run; proc contents data=bootsales; /*#5*/ run; proc print data=bootsales; run;
1 | The VALIDVARNAME=V7 statement forces SAS to convert spaces to underscores when it converts column names to variable names. In SAS Studio, the _ (underscore) in Total_Sale would not be added without the VALIDVARNAME=V7 statement. |
2 | Specify the input file. DATAFILE= specifies the path for the input file. The DBMS= option specifies the type of data to import. When importing an Excel workbook, specify DBMS=XLSX. The REPLACE option overwrites an existing SAS data set. The OUT= option identifies the output SAS data set. |
3 | Use the SHEET option to import specific worksheets from an Excel workbook. |
4 | Set the GETNAMES= statement to YES to generate variable names from the first row of data. |
5 | Use the CONTENTS procedure to display the descriptor portion of the Work.BootSales data set. |
75 options validvarname=v7; 76 proc import datafile='C:UsersStudent1certoots.xlsx' 77 dbms=xlsx 78 out=work.bootsales replace; 79 sheet=boot; 80 getnames=yes; 81 run; NOTE: Variable Name Change. Total Sale -> Total_Sale NOTE: The import data set has 10 observations and 3 variables. NOTE: WORK.BOOTSALES data set was successfully created.
options validvarname=v7; proc import datafile='C:UsersStudent1certdelimiter.txt' /*#1*/ dbms=dlm /*#2*/ out=mydata replace; delimiter='&'; /*#3*/ getnames=yes; /*#4*/ run; proc print data=mydata; run;
1 | Specify the input file. DATAFILE= specifies the path for the input file. The DBMS= option specifies the type of data to import. |
2 | If the delimiter is a character other than TAB or CSV, then the DBMS= option is DLM. The REPLACE option overwrites an existing SAS data set. The OUT= option identifies the output SAS data set. |
3 | Specify an ampersand (&) for the DELIMITER statement. |
4 | Set the GETNAMES= statement to YES to generate variable names from the first row of data. |
Region State Capital Bird South Georgia Atlanta 'Brown Thrasher' South 'North Carolina' Raleigh Cardinal North Connecticut Hartford Robin West Washington Olympia 'American Goldfinch' Midwest Illinois Springfield Cardinal
options validvarname=v7; filename stdata 'C:UsersStudent1certstate_data.txt' lrecl=100; /*#1*/ proc import datafile=stdata /*#2*/ dbms=dlm out=states replace; delimiter=' '; /*#3*/ getnames=yes; run; proc print data=states; run;
1 | Specify the fileref and the location of the file. Specify the LRECL= system option if the file has a fixed-length format. The LRECL= system option specifies the default logical record length to use when reading external files. |
2 | Specify the input file and specify that it is a delimited file. The DBMS= option specifies the type of data to import. If the delimiter type is a character other than TAB or CSV, then the DBMS= option is DLM. The REPLACE option overwrites an existing SAS data set. The OUT= option identifies the output SAS data set. |
3 | Specify a blank value for the DELIMITER statement. Set the GETNAMES= statement to YES to generate variable names from the first row of data. |
options validvarname=v7; proc import datafile='C:UsersStudent1certoot.csv' /*#1*/ dbms=csv out=shoes replace; getnames=no; /*#2*/ run; proc print data=work.shoes; run;
1 | Specify the input file. DATAFILE= specifies the input data file, and OUT= specifies the output data set. The DBMS= specifies the type of data to import. If the file type is CSV, then the DBMS= option is CSV. The REPLACE option overwrites an existing SAS data set. |
2 | Set the GETNAMES= statement to NO to not use the first row of data as variable names. |
proc import datafile='C:UsersStudent1certclass.txt' /*#1*/ dbms=tab out=class replace; delimiter='09'x; /*#2*/ run; proc print data=class; run;
1 | Specify the input file. DATAFILE= specifies the input data file, and OUT= specifies the output data set. DBMS= specifies the type of data to import. If the file type is TXT, then the DBMS= option is TAB. The REPLACE option overwrites an existing SAS data set. GETNAMES= statement defaults to YES. |
2 | Specify the delimiter. On an ASCII platform, the hexadecimal representation of a tab is '09'x. On an EBCDIC platform, the hexadecimal representation of a tab is a '05'x. |