Previous Page | Next Page

The DBF and DIF Procedures

The DBF Procedure



Converts a dBASE file to SAS data set or a SAS data set to a dBASE file.
Syntax
PROC DBF Options
Details
Converting DBF Fields to SAS Variables
Converting SAS Variables to DBF Fields
Transferring Other Software Files to DBF Files
Examples: UNIX
Converting a dBASE II File to a SAS Data Set
Converting a SAS Data Set to a dBASE 5 File
Creating a DBF file from a SAS Data Set in a Microsoft Windows Environment
IBM z/OS Environment

Syntax

PROC DBF <option(s)>

PROC DBF Options

DB2|DB3|DB4|DB5=fileref|filename

specifies the version of the dBase file and the fileref or filename of a DBF file. The DBn option must correspond to the version of dBASE with which the DBF file is compatible. Specify the version with the DBn 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;
Requirement: You must specify a FILENAME statement.
Requirement: The DBn= option is required.
Restriction: You cannot specify the filename extension .dbf or a full pathname PROC DBF DB5='/my/unix_directory/emp.dbf' .
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 [...Datan]. Under Microsoft Windows, it is called _DATA_). The WORK data set remains available only during your current SAS session.


Details

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.

Future versions of dBASE files might not be compatible with the current version of the DBF procedure.


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.


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.


Transferring Other Software Files to DBF Files

You might find 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 [arrow]  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.


Examples: UNIX


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

In this example, a 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 2: Converting a SAS Data Set to a dBASE 5 File

In this example, a SAS data set is converted to a dBASE 5 file. A FILENAME statement specifies a fileref that names the dBASE 5 file. You must specify the FILENAME statement before the PROC DBF statement.

LIBNAME mylib '/my/unix_directory';
FILENAME employee '/sasdemo/employee.dbf';
PROC DBF DB5=employee DATA=mylib.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: IBM z/OS Environment

LIBNAME mylib 'sasdemo.employee.data';
FILENAME dbfout 'sasdemo.newemp.dbf' RECFM=n;
PROC DBF DB5=dbfout DATA=mylib.employee;
RUN;

Previous Page | Next Page | Top of Page