![]() | ![]() | ![]() | ![]() | ![]() |
Note: PROC IMPORT is only available on the following operating systems: OS/2, UNIX, OpenVMS, and Windows.
For more information and additional documentation on
PROC IMPORT, see the SAS Procedures Guide.
/*******************************************************************************/
/* PROC IMPORT reads data from a delimited file (DATAFILE=) and writes it to a */
/* SAS data set (OUT=). If the file to be read has an extension of CSV, */
/* specify DBMS=CSV. If the file to be read is tab delimited, use DBMS=TAB. */
/* For all other delimited files, use DBMS=DLM. By default, the delimiter is */
/* assumed to be a space. If it is not, use the DELIMITER= option to indicate */
/* the correct delimiter. */
/* */
/* The optional statement GETNAMES= indicates whether the first record of the */
/* file is to be used as the variable names. */
/* */
/* Beginning in SAS 9.1, GUESSINGROWS= is also available to specify how many */
/* rows of data are to be sampled to determine variable attributes. Prior */
/* to SAS 9.1 the value of GUESSINGROWS was changed by editing the registry: */
/* How to scan more than 20 records to determine variable attributes in EFI. */
/* */
/* Please refer to the SAS Procedures Guide for more details and additional */
/* options and statements. */
/*******************************************************************************/
/* Example 1: Reading an exclamation point (!) delimited file with */
/* variable names on the first row */
/* Create test file to read using PROC IMPORT below. */
data _null_;
file 'c:\temp\pipefile.txt';
put"X1!X2!X3!X4";
put "11!22!.! ";
put "111!.!333!apple";
run;
/* By default, it is assumed the variable names are on the first row, so the */
/* GETNAMES= statement is not required. */
proc import
datafile='c:\temp\pipefile.txt'
out=work.test
dbms=dlm
replace; /* note this is the first semi-colon */
delimiter='!';
getnames=yes;
run;
proc print;
run;
/* Example 2: Reading a comma delimited file with a .csv extension */
/* */
/* Since the DBMS= value is CSV, you do not have to use the DELIMITER= */
/* statement. By default, it is assumed the variable names are on the first */
/* row, so the GETNAMES= statement is not required. */
/* Create comma delimited test file to read using PROC IMPORT below. */
data _null_;
file 'c:\temp\csvfile.csv';
put "Fruit1,Fruit2,Fruit3,Fruit4";
put "apple,banana,coconut,date";
put "apricot,berry,crabapple,dewberry";
run;
proc import
datafile='c:\temp\csvfile.csv'
out=work.fruit
dbms=csv
replace;
run;
proc print;
run;
/* Example 3: Reading a tab delimited file */
/* */
/* Since the DBMS= value is TAB, you do not have to use the DELIMITER= */
/* statement. If the data starts on the first record, specify */
/* GETNAMES= NO. By default, the variable names will be VAR1, VAR2...VARn. */
/* Create tab delimited test file to read using PROC IMPORT below. */
data _null_;
file 'c:\temp\tabfile.txt';
put "cereal" "09"x "eggs" "09"x "bacon";
put "muffin" "09"x "berries" "09"x "toast";
run;
proc import
datafile='c:\temp\tabfile.txt'
out=work.breakfast
dbms=tab
replace;
getnames=no;
run;
proc print;
run;RESULTS -- Example 1 Obs X1 X2 X3 X4 1 11 22 . 2 111 . 333 apple RESULTS -- Example 2 Obs Fruit1 Fruit2 Fruit3 Fruit4 1 apple banana coconut date 2 apricot berry crabapple dewberry RESULTS -- Example 3 Obs VAR1 VAR2 VAR3 1 cereal eggs bacon 2 muffin berries toast
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Procedures ==> IMPORT Common Programming Tasks ==> Reading and Writing External Data |
| Date Modified: | 2007-01-17 03:03:08 |
| Date Created: | 2004-09-30 14:09:01 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | Tru64 UNIX | 8 TS M0 | n/a |
| Solaris | 8 TS M0 | n/a | ||
| OpenVMS Alpha | 8 TS M0 | n/a | ||
| Linux | 8 TS M0 | n/a | ||
| HP-UX | 8 TS M0 | n/a | ||
| HP-UX IPF | 8 TS M0 | n/a | ||
| AIX | 8 TS M0 | n/a | ||
| 64-bit Enabled Solaris | 8 TS M0 | n/a | ||
| ABI+ for Intel Architecture | 8 TS M0 | n/a | ||
| 64-bit Enabled HP-UX | 8 TS M0 | n/a | ||
| 64-bit Enabled AIX | 8 TS M0 | n/a | ||
| OS/2 | 8 TS M0 | n/a | ||





