본문 바로가기

기타

sas - proc dbf : dbf 파일 읽는 법

Converting DBF Fields to SAS Variables

When you convert a DBF file to a 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 254 is truncated to 254 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.


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 Procedure: z/OS).

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.



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

In this example, a dBASE IV file named SASDEMO.EMPLOYEE.DBF 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, as shown:

libname save 'sasdemo.employee.data';
filename dbfin 'sasdemo.employee.dbf';
proc dbf db4=dbfin out=save.employee;
run;


Example 2: Converting a dBASE 5 file to a SAS Data Set

In this example, a dBASE 5 file is converted to a SAS data set.

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


filename sudo80 'D:\Thesis\인구집중 논문\sudo80.dbf';
proc dbf db4=sudo80 out=dong80;

data dong801;set dong80;
rename sgg_nm=gu_name;
rename emd_nm=dong_name;
data dong802;
length dong_name $ 15.0;
set dong801;
proc sort;by dongname;

filename sudonm 'D:\Thesis\인구집중 논문\pop_80_sudo1.dbf';
proc dbf db4=sudonm out=dongnm2;
proc sort;by dong_name;

data a11;merge dong802 dongnm2;by dong_name;
proc print;
run;