The DBF Procedure

Convert a data interchange format (DBF) files to SAS data sets.

Syntax

PROC DBF option(s)

Required Argument

DB2 | DB3 | DB4 | DB5 =fileref |filename
specifies the version of the dBase file and the fileref or filename of a DBF file. The DB n option must correspond to the version of dBASE with which the DBF file is compatible. Specify the version with the DB n option, where n is the version number. The values are 2, 3, 4, or 5.
To specify a fileref, the FILENAME statement must specify the filename with a .dbf extension. This example assigns the fileref myref to the file '/my_dir/myfile.dbf':
filename myref '/my_dir/myfile.dbf';
If you specify a filename instead of a fileref, specify the filename without the .dbf extension. The file must be in the current directory, in uppercase.
The following PROC DBF statement creates the EMP.DBF file (with the name in uppercase) from the MyLib.Employee data set:
PROC DBF DB5=emp DATA=mylib.employee;
Restriction:You cannot specify the filename extension .dbf or a full pathname. PROC DBF DB5='/my/unix_directory/emp.dbf'.
Requirements:You must specify a FILENAME statement.

The DB n = option is required.

Optional Arguments

DATA= <libref>.member
specifies the name of the SAS data set you are reading to create a DBF file. If you omit the DATA= option, SAS creates an output SAS data set from the DBF file. The output file is written to the temporary WORK directory. The naming convention is Data1, Data2, DataN. The temporary WORK file is available only during your current SAS session.
OUT=<libref.>member
specifies the name of the SAS data set you are creating from a DBF file. If you omit the OUT= option, SAS creates an output SAS data set from the DBF file. Use this option only if you are creating a SAS data set from a DBF file and you did not specify the DATA= option.
If OUT= is omitted, SAS creates a temporary data set in the Work library. (Under UNIX, the temporary data set is named Data1, ..., Data n]. Under Microsoft Windows, it is called _DATA_). The WORK data set remains available only during your current SAS session.

Details

Overview

The DBF procedure converts data interchange format (DBF) files to SAS data sets. The data sets are compatible with the current release of SAS software, or SAS data sets convert to DBF files.
PROC DBF produces one output file but no printed output. The output file contains the same information as the input file but in a different format.
Software Arts, Inc. developed the data interchange format to be used as a common language for data. Originally, DBF was made popular by products such as Lotus 1-2-3 and VisiCalc. Although DBF is not as popular today, it is still supported by many software products.
When you are converting a DBF file, each row of the file becomes an observation in the SAS data set. Conversely, when you are converting a SAS data set, each SAS observation becomes a row in the DBF file. To use the DBF procedure, you must have a SAS/ACCESS Interface to PC Files license.
Note: Any DBF file that you plan to import to a SAS data set should be in a tabular format. All items in a given column should represent the same type of data. If the DBF file contains inconsistent data, such as a row of underscores, hyphens, or blanks, delete these rows before converting the file. It is recommended that you make a backup copy of your DBF table before you make these modifications.

Converting DBF Fields to SAS Variables

Numeric variables are stored in character form by DBF files. These numeric variables become SAS numeric variables when converted from a DBF file to a SAS data set. If a DBF numeric value is missing, the corresponding dBASE numeric field is filled with the character 9 by default.
Character variables become SAS character variables. Logical fields become SAS character variables with a length of 1. Date fields become SAS date variables. When you are converting a DBF file to a SAS data set, fields with data stored in auxiliary DBF files (Memo and General fields) are ignored.
When a dBASE II file is translated into a SAS data set, any colons in dBASE variable names are changed to underscores in SAS variable names. Conversely, when a SAS data set is translated into a dBASE file, any underscores in SAS variable names are changed to colons in dBASE field names.
The DBF procedure converts dBASE files to SAS data sets that are compatible with the current release of SAS, or it converts SAS data sets to DBF files.
The DBF procedure produces one output file but no printed output. The output file contains the same information as the input file but in a different format.
The DBF procedure supports DBF files that are dBASE (II, III, III PLUS, IV, and 5.0) versions and releases. The DBF procedure supports most DBF files that other software products create.
Note: Future versions of dBASE files might not be compatible with the current version of the DBF procedure.

Converting SAS Variables to DBF Fields

Numeric variables are stored in character form by DBF files. SAS numeric variables become numeric variables with a length of 16 when converted from a DBF file. SAS decimal values must be stored in a decimal format to be converted to a DBF decimal value. Associate the SAS numeric variable with an appropriate decimal format. The corresponding DBF field does not have any value to the right of the decimal point. You can associate a format with SAS variables when you create the data set or with the DATASETS procedure.
If the number of digits including a possible decimal point exceeds 16, a warning message is issued and the DBF numeric field is filled with the character 9. All SAS character variables become DBF fields of the same length. When you convert a SAS data set to a DBF file that is compatible with dBASE III or later, SAS date variables become DBF date fields. When you convert a SAS data set to a dBASE II file, SAS date variables become dBASE II character fields in the form YYYYMMDD.
If the number of digits including a possible decimal point exceeds 16, a warning message is issued and the DBF numeric field is filled with the character 9. All SAS character variables become DBF fields of the same length. When you convert a SAS data set to a DBF file that is compatible with dBASE III or later, SAS date variables become DBF date fields. When you convert a SAS data set to a dBASE II file, SAS date variables become dBASE II character fields in the form YYYYMMDD

Transferring Other Software Files to DBF Files

You might find File it helpful to save another software vendor's file to a DBF file and then convert that file into a SAS data set. UNIX users find this especially helpful. For example, you could save an Excel XLS file to a DBF file (by selecting File then selectSave as from within an Excel spreadsheet Select ( Emp.dbf file) and use PROC DBF to convert that file into a SAS data set.
You could also do the reverse: use PROC DBF to convert a SAS data set into a DBF file and then load the DBF file into the Excel spreadsheet.

Examples

Example 1: Converting a SAS Data Set to a dBASE 5 File

Filethen select Save As from within an Excel spreadsheet and selecting the Emp.dbf file) and then use PROC DBF to convert that file into a SAS data set. Or you could do the reverse: use PROC DBF to convert a SAS data set into a DBF file and then load that file into an Excel spreadsheet
LIBNAME mylib '/my/unix_directory';
FILENAME employee '/sasdemo/employee.dbf';
PROC DBF DB5=employee DATA=mylib.employee;
RUN;

Example 2: Converting a dBASE II File to a SAS Data Set on UNIX

The dBASE II file named Employee.dbf is converted to a SAS data set. No FILENAME statement is specified so the last level of the filename is .dbf. The file is assumed to be in your current directory and in uppercase.
LIBNAME save '/my/unx_save_dir';
PROC DBF DB2=employee OUT=save.employee;
RUN;

Example 3: Creating a DBF File from a SAS Data Set in a Microsoft Windows Environment

In this example, the mylib.employee SAS data set is converted to a dBASE 5 file. The FILENAME statement specifies the name of the DBF file. You must specify the FILENAME statement before the PROC DBF statement.
LIBNAME mylib 'c:\my\directory';
FILENAME employee 'c:\sasdemo\employee.dbf';
PROC DBF DB5=employee DATA=mylib.employee;
RUN;

Example 4: Creating a DBF File from a SAS Data Set in a z/OS Environment

This example is the same as the previous example - for the z/OS environment.
LIBNAME mylib 'sasdemo.employee.data';
FILENAME dbfout 'sasdemo.newemp.dbf' RECFM=n;
PROC DBF DB5=dbfout DATA=mylib.employee;
RUN;