Chapter Contents

Previous

Next
PROC DBF

PROC DBF



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
Example 1: Converting a dBASE II File to a SAS Data Set
Example 2: Converting a SAS Data Set to a dBASE 5 File

Syntax

PROC DBF options;

PROC DBF Options

DB2|DB3|DB4|DB5=fileref | filename
specifies the fileref or filename of a DBF file. When you use the FILENAME statement to assign the fileref, the statement must specify the filename plus a DBF extension (that is, filename myref '/my_dir/myfile.dbf').

If you specify a filename instead of a fileref, you can only specify the name itself (omitting the DBF extension) and the file must be in the current directory. For example, this PROC DBF statement creates the EMP.DBF file (uppercase) from the MYLIB.EMPLOYEE data set:

proc dbf db5=emp data=mylib.employee;
You cannot specify emp.dbf or a full pathname ( proc dbf db5='/my/unix_directory/emp.dbf') in the DBn= option.

The DBn option must correspond to the version of dBASE with which the DBF file is compatible. You specify a DBF file with the DBn option, where n is 2, 3, 4, or 5. You can specify only one of these values. If you specify DB4=myfile, SAS looks for (and creates, depending on your options) a file called MYFILE.DBF, where the name is converted to uppercase.

DATA=<libref.>member
names the input SAS data set. Use this option if you are creating a DBF file from a SAS data set. If you use the DATA= option, do not use the OUT= option. If you omit the DATA= option, SAS software creates an output SAS data set from the DBF file.

OUT=<libref.>member
names the SAS data set that is created to hold the converted data. Use this option only if you do not specify the DATA= option.

If OUT= is omitted, SAS creates a temporary data set in the WORK library. (Under UNIX and OS/390, the temporary data set is named DATA1 [...DATAn]; under PCs, it is called _DATA_.) If OUT= is omitted or if you do not specify a two-level name in the OUT= option, the SAS data set that is created by PROC DBF remains available during your current SAS session, but it is not permanently saved.


Details

The DBF procedure converts dBASE files to SAS data sets that are compatible with the current release of the SAS System. This procedure can also be used to convert SAS data sets 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.

The DBF procedure works with DBF files created by all the current versions and releases of dBASE (II, III, III PLUS, IV, and 5.0) and with most DBF files that are created by other software products.

Future versions of dBASE files might not be compatible with the current version of the DBF procedure. SAS Institute cannot be responsible for upgrading PROC DBF to support new versions of dBASE with each new version of SAS software. To use the DBF procedure, you must have a SAS/ACCESS interface to PC File Formats license.


Converting DBF Fields to SAS Variables

Numeric variables are stored in character form by DBF files. These numeric variables become SAS numeric variables when converting 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. Any character variable of a length greater than 200 is truncated to 200. Logical fields become SAS character variables with a length of 1. Date fields become SAS date variables. When converting a DBF file to a SAS data set, fields whose data are 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 converting from a SAS data set to a DBF file. A SAS numeric variable with a decimal value must be stored in a decimal format in order to be converted to a DBF numeric field with a decimal value. In other words, unless you associate the SAS numeric variable with an appropriate format in a SAS FORMAT statement, the corresponding DBF field will not have any value to the right of the decimal point. You can associate a format with the variable in a SAS data set when you create the data set or by using 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 converting from a SAS data set to a DBF file that is compatible with dBASE III or later, SAS date variables become DBF date fields. When converting from a SAS data set to a dBASE II file, SAS date variables become dBASE II character fields in the form YYYMMDD.


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 --> Save As -->EMP.DBF from within an Excel spreadsheet) 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

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. Because no FILENAME statement is specified, the last level of the filename is assumed to be DBF and 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;

In a Windows environment, this example would be:

libname mylib 'c:\my\directory';
filename employee 'c:\sasdemo\employee.dbf';
proc dbf db5=employee data=mylib.employee;
run;

In an OS/390 environment, this example would be:

libname mylib 'sasdemo.employee.data';
filename dbfout 'sasdemo.newemp.dbf' recfm=n;
proc dbf db5=dbfout data=mylib.employee;
run;


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.