| File Format-Specific Reference for IMPORT and EXPORT Procedures |
| DBF Files Essentials |
This section introduces dBase DBF files. It focuses on the terms and concepts that help you use SAS/ACCESS Interface to PC Files.
DBF files are in a file format that dBASE creates. dBASE is a relational database management system for PC systems. DBF files can be created using a variety of PC software programs, such as Microsoft Visual FoxPro.
A DBF file contains data that is organized in a tabular format of database fields and records. Each database field can contain one type of data, and each record can hold one data value for each field. The following picture illustrates four database fields from Customer.DBF and highlights a database field and a record.
![[DBF file]](images/dbffig1.gif)
| DBF Data Types |
Every field in a DBF file has a name and a data type. The data type tells how much physical storage to set aside for the database field and the form in which the data is stored. The following list describes each data type.
dBASE also has data types called Memo, General, binary, and OLE. These data types are stored in an associated memo text file (a DBT file), but these data types are not supported in the SAS/ACCESS Interface to PC Ffiles.
| Setting Environment Variables and System Options |
| Missing Values |
Missing numeric values are filled in with blanks by default. The DBFMISCH environment variable is used to change the default by specifying the character that the interface to DBF files uses to fill missing numeric fields. For example, if you try to write a SAS file with a missing numeric variable to a DBF file, the corresponding field in the DBF file would be filled with the DBFMISCH character. Conversely, any numeric or float field in a DBF file that is filled with the DBFMISCH character is treated as missing when read by SAS. You set the DBMISCH environment variable in the SAS configuration file using the following syntax: -set DBFMISCH value Here are the valid values: |
| NULLS |
To replace missing numeric values with binary zeros, enter -set DBFMISCH NULLS . |
| BLANKS |
To replace missing numeric values with blanks, enter -set DBFMISCH BLANKS. |
| Decimal Separator |
Although a period is used as decimal separator in the United States, some countries might use different symbol characters. For example, some European countries use comma character as the decimal separator. To allow data saved with different decimal separator to be imported or exported correctly, you must set SAS system option, CTRYDECIMALSEPARATOR. You set CTRYDECIMALSEPARATOR option in the SAS using the following syntax: options CTRYDECIMALSEPARATOR=value; Valid values can be any character. For example, European users might set a comma as the decimal separator by submitting the following statement in SAS: |
options CTRYDECIMALSEPARATOR=',' ;
| Supported SAS IMPORT/EXPORT Procedure Statements |
This Import/Export component uses DBF file formats to access data in DBF Files on Linux, UNIX, and Microsoft Windows operating platforms. It imports data from DBF files that were saved in Version 3, Version 4, and Version 5 formats. It exports data to DBF files with Version 5 formats.
The following table lists the statements that are available for processing DBF files in IMPORT and EXPORT procedures. See Examples of Importing and Exporting DBF Files.
| Data Source | Syntax | Valid Values | Default Value | In PROC IMPORT? | In PROC EXPORT? |
| DBF | DBENCODING= | Encoding-value | Current SAS session encoding | Yes | Yes |
|
|
GETDELETED= | YES | NO | YES | Yes | No |
Indicates the encoding used to save data in DBF files. An encoding maps each character in a character set to a unique numeric representation, which results in a table of all code points. A single character can have different numeric representations in different encodings.
For example, some DBF files were saved with pcoem850 encoding. When you are importing these DBF files on Microsoft Windows, specify DBENCODING=pcoem850. SAS IMPORT procedure reads and transcodes data from pcoem850 to Microsoft Windows default WLATIN1.
Refer to the SAS NLS User's Guide for more information about transcoding and valid encoding values.
indicates whether to write records to the SAS data sets that are marked for deletion but have not been purged.
| YES |
writes records to the SAS data sets that are marked for deletion but have not been purged. |
| NO |
does not write records to the SAS data sets that are marked for deletion but have not been purged. |
| Examples of Importing and Exporting DBF Files |
Export Data to a DBF File from a SAS Data Set
The following example code exports data to a DBF file, named test.dbf, from a SAS data set named SDF.EMPLOYEE, with a WHERE condition in the data set option.
LIBNAME SDF V9 "&sasdir"; PROC EXPORT DATA=SDF.EMPLOYEE (where=(HIREDATE is not missing)) OUTFILE="&tmpdir.test.dbf" DBMS=DBF REPLACE; RUN;
Import Data from a DBF File into a SAS Data Set
The following example code imports data from a DBF file named invoice.dbf into SAS data set named TEST5. The data is imported without the DELETE flag field.
PROC IMPORT OUT=WORK.TEST5 DATAFILE="&dbfdir.Invoice.dbf" DBMS=DBF REPLACE; GETDEL=NO; RUN;
Export Data to a DBF File from a SAS Data SAS Using Encoding
The following example code exports data to a DBF file named Oem850.dbf from a SAS data set named SDF.ORDERS. The example code translates SAS data from its current session encoding to pcoem850 encoding and writes it to the DBF file.
PROC EXPORT DATA=SDF.ORDERS OUTFILE="&dbfdir.Oem850.dbf" DBMS=DBF REPLACE; DBENCODING=pcoem850; RUN;
Import and Translate Data from a DBF File
The following example code imports data from a DBF file named Oem850.dbf, which was saved with pcoem850 encoding. The codes read in the data and translates it from pcoem850 encoding to current SAS session encoding.
PROC IMPORT OUT=WORK.ORDERS DATAFILE="&dbfdir.Oem850.dbf" DBMS=DBF REPLACE; DBENCODING=pcoem850; RUN;
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.