Chapter Contents |
Previous |
Next |
DBF |
CMS specifics: | all |
Syntax |
PROC DBF options; |
The DBn option must correspond to the version of dBASE with which the DBF file is compatible. Specify a DBF file with the DBn option, where n is 2, 3, 4, or 5. You can only specify one of these values.
Details |
You can use PROC DBF in the CMS environment if your site has a license for SAS/ACCESS for PC File Formats. To see a list of your licenses, submit the following statements:
proc setinit; run;
If you are licensed you will see an entry in your SAS log for SAS/ACCESS for PC File Formats.
The DBF procedure converts files in DBF format to SAS data sets that are compatible with the current SAS release. You can also use PROC DBF to convert SAS data sets to files in DBF format.
Before you convert a DBF file to a SAS file, you must first upload your DBF file from the Windows, OS/2, NT, or UNIX environment to the CMS environment, using a mechanism such as FTP (file transfer protocol). If you are licensed for SAS/CONNECT, you can use PROC UPLOAD:
filename out1 'sasdemo.emp.dbf'; proc upload infile='c:\employee\emp.dbf' outfile=out1 binary; run;
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.
Converting DBF Fields to SAS Variables |
When you convert a DBF file a to SAS data set, DBF numeric variables become SAS numeric variables. Similarly, DBF character variables become SAS character variables. Any DBF character variable of length greater than 200 is truncated to 200 in SAS. Logical fields become SAS character variables with a length of 1. Date fields become SAS date variables.
DBF fields whose data are stored in auxiliary files (Memo, General, binary, and OLE data types) are ignored in SAS.
If a DBF file has missing numeric or date fields, SAS fills those missing fields with a series of the digit '9' or with blanks, respectively.
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.
Example 1: Converting a dBASE IV File to a SAS Data Set |
In this example, a dBASE IV file named SASDEMO.EMPLOYEE is converted to a SAS data set. A FILENAME statement specifies a fileref that names the dBASE IV file. The FILENAME statement must appear before the PROC DBF statement.
libname save 'sasdemo.employee.data'; filename dbfin 'sasdemo.employee dbf a'; proc dbf db4=dbfin out=save.employee; run;
Example 2: Converting a dBASE 5 file to a SAS Data Set |
In this example, a SAS data set is converted to a dBASE 5 file.
libname demo 'sasdemo.employee.data'; filename dbfout 'newemp dbf a' recfm=n; proc dbf db5=dbfout data=demo.employee; run;
Converting SAS Variables to DBF Fields |
In DBF files, numeric variables are stored in character form. When converting from a SAS data set to a DBF file, SAS numeric variables become DBF numeric variables with a total length of 16. 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 (see DATASETS).
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 a series of the digit '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 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. For example, you could save an Excel XLS file in DBF format, upload the file, and 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.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.