Previous Page | Next Page

Using SAS Files under Windows

Reading BMDP, OSIRIS, and SPSS Files

SAS 9.2 provides three interface library engines that enable you to access external data files directly from a SAS program: the BMDP, OSIRIS, and SPSS engines. These engines are all read-only. Because they are sequential engines (that is, they do not support random access of data), these engines cannot be used with the POINT= option in the SET statement or with the FSBROWSE, FSEDIT, or FSVIEW procedures. When using BMDP and OSIRIS engines, you can use PROC COPY or a DATA step to copy the system file to a SAS data set and then perform these functions on the SAS data set. When using the SPSS engine, PROC COPY or a DATA step will support the portable file format. Also, because they are sequential engines, some procedures (such as the PRINT procedure) give a warning message that the engine is sequential. With these engines, the physical filename that is associated with a libref is an actual filename, not a folder. This action is an exception to the rules concerning librefs.

You can also use the CONVERT procedure to convert BMDP, OSIRIS, and SPSS files to SAS data files. For more information, see CONVERT Procedure: Windows.


BMDP Engine

The BMDP interface library engine enables you to read BMDP DOS files from the BMDP statistical software package directly from a SAS program. The following sections assume that you are familiar with the BMDP save file terminology.

To read a BMDP save file, you must issue a LIBNAME statement that explicitly specifies that you want to use the BMDP engine:

LIBNAME libref BMDP <'filename'>;

In this form of the LIBNAME statement, libref is a SAS libref and filename is the BMDP physical filename. If the libref appears previously as a fileref, you can omit filename because the physical filename that is associated with the fileref is used. This engine can read only BMDP save files created under DOS.

Because there can be multiple save files in a single physical file, you reference the CODE= value as the member name of the data set within the SAS language. For example, if the save file contains CODE=ABC and CODE=DEF and the libref is MYLIB, you reference them as MYLIB.ABC and MYLIB.DEF. All CONTENT types are treated the same. Therefore, even if member DEF is CONTENT=CORR, it is treated as CONTENT=DATA.

If you know that you want to access the first save file in the physical file, or if there is only one save file, you can refer to the member name as _FIRST_. This convention is convenient if you do not know the CODE= value.


BMDP Engine Examples

In the following example, the physical file MYBMDP.DAT contains the save file ABC. This example associates the libref MYLIB with the BMDP physical file, and then runs the CONTENTS and PRINT procedures on the save file:

   libname mylib bmdp 'mybmdp.dat';
   proc contents data=mylib.abc;
   run;
   proc print data=mylib.abc;
   run;

The following example uses the LIBNAME statement to associate the libref MYLIB2 with the BMDP physical file. Then it prints the data for the first save file in the physical file:

   libname mylib2 bmdp 'mybmdp.dat';
   proc print dat=mylib2._first_;
   run;


OSIRIS Engine

Because the Inter-University Consortium on Policy and Social Research (ICPSR) uses the OSIRIS file format for distribution of its data files, SAS provides the OSIRIS interface library engine to support ICPSR data users and to be compatible with PROC CONVERT, which is described in CONVERT Procedure: Windows.

The read-only OSIRIS engine enables you to read OSIRIS data and dictionary files directly from a SAS program. These files must be stored in EBCDIC format. This action assumes that you downloaded the OSIRIS files from your host computer in binary format. The following section assumes that you are familiar with the OSIRIS file terminology. (footnote 1)

To read an OSIRIS file, you must issue a LIBNAME statement that explicitly specifies you want to use the OSIRIS engine. In this case, the LIBNAME statement takes the following form:

LIBNAME libref OSIRIS 'data-filename' DICT='dictionary-filename';

In this form of the LIBNAME statement, libref is a SAS libref, data-filename is the physical filename of the OSIRIS data file, and dictionary-filename is the physical filename of the OSIRIS dictionary file. The dictionary-filename argument can also be an environment variable name or a fileref. (Do not use quotation marks if it is an environment variable name or fileref.) The DICT= option must appear because the engine requires both files.

OSIRIS data files do not have member names. Therefore, you can use whatever member name you like. You can use the same OSIRIS dictionary file with different OSIRIS data files. Write a separate LIBNAME statement for each one.

The layout of an OSIRIS data dictionary is consistent across operating environments. The reason is that the OSIRIS software does not run outside the z/OS environment, but the engine is designed to accept an z/OS data dictionary on any other operating environment under which SAS runs. It is important that the OSIRIS dictionary and data files not be converted from EBCDIC to ASCII; the engine expects EBCDIC data. There is no specific file layout for the OSIRIS data file. The file layout is controlled by the contents of the OSIRIS dictionary file.


OSIRIS Engine Example

In the following example, the data file is MYOSIRIS.DAT, and the dictionary file is MYOSIRIS.DIC. The example associates the libref MYLIB with the OSIRIS files and then runs PROC CONTENTS and PROC PRINT on the data:

libname mylib osiris 'myosiris.dat' 
        dict='myosiris.dic';
proc contents data=mylib._first_;
run;
proc print data=mylib._first_;
run;


SPSS Engine

The SPSS interface library engine enables you to read SPSS export files directly from a SAS program. The SPSS export file must be created by using the SPSS EXPORT command. (footnote 2)The SPSS engine is a read-only engine.

To read an SPSS export file you must issue a LIBNAME statement that explicitly specifies that you want to use the SPSS engine. In this case, the LIBNAME statement takes the following form:

LIBNAME libref SPSS <'filename'>;

In this form of the LIBNAME statement, the libref argument is a SAS libref, and filename is the SPSS physical filename, including the file extension. If the libref appears also as a fileref, you can omit filename because the physical filename that is associated with the fileref is used. The SPSS native file format is not supported. Export files can originate from any operating environment.

Because SPSS files do not have internal names, you can refer to them by any member name that you like. (The example in this discussion uses _FIRST_ .)

Note:   SPSS can have system-missing and user-defined missing data. When you use the SPSS engine or PROC CONVERT, the missing values (user-defined or system) are converted to system-missing values. User-defined missing values have to be recoded as valid values. When the data set is converted, you can use PROC FORMAT to make the translation. For example, -1 to .A and -2 to .B.  [cautionend]


SPSS Engine Example

The following example associates the libref MYLIB with the physical file MYSPSS.POR in order to run PROC CONTENTS and PROC PRINT on the portable file:

libname mylib spss 'myspss.por';
proc contents data=mylib._first_;
run;
proc print data=mylib._first_;
run;


Reformatting SPSS Files

SAS cannot use an SPSS file that contains a variable that has a numeric format which has a larger number of decimal places than the width of the entire variable. For example, if an SPSS file has a variable that has a width of 17 and also has 35 decimal places, SAS will return errors when you try to run a DATA step on the file or when you try to view it with the table viewer. To use the SPSS file with SAS, you must reformat the variable.

You can reformat the variable by reducing the number of decimal spaces to a value that fits within the width of the variable. In the following code, the statement revision=cat(format,formatl,'.2'); converts the number of decimal spaces to 2. This value reduces the number of decimal spaces so that it is not greater than the width of the variable.

libname abc spss 'FILENAME.POR';
proc contents data=abc._all_ out=new; run;
filename sascode temp;
data _null_; set new; file sascode;
     if formatd > formatl then do;
        revision=cat(format,formatl,'.2');
        put 'format' +1 name +1 revision ';' ;
        end;
     run;
data temp; set abc._all_;
     %inc sascode/source2;
     run;

Note:   The OPTIONS NOFMTERR statement does not allow SAS to use a data set that has a DATA step or the table viewer. You must reformat numeric variables that have a larger decimal space value than their width before you can use a DATA step or the table viewer.  [cautionend]


FOOTNOTE 1:   See documentation provided by the Institute for Social Research for more information. [arrow]

FOOTNOTE 2:   See documentation provided by SPSS Inc. for more information. [arrow]

Previous Page | Next Page | Top of Page