Previous Page | Next Page

Using SAS Files

Accessing BMDP, OSIRIS, or SPSS Files in UNIX Environments


Introduction to the BMDP, OSIRIS, and SPSS Files

SAS includes three interface library engines, BMDP, OSIRIS, and SPSS, that enable you to access external data directly from a SAS program. All of these engines are read-only.

Because they are sequential, these engines cannot be used with the POINT= option in the SET statement, or with the FSBROWSE, FSEDIT, or FSVIEW procedures. You can use PROC COPY, PROC DATASETS, or a DATA step to copy a BMDP or OSIRIS system file or an SPSS export file to a SAS data set, and then perform these functions on the SAS data set. Also, some procedures (such as PROC PRINT) give a warning message about the engine being sequential.

With these engines, the physical filename that is associated with a libref is an actual filename, not a directory. This association is an exception to the rules concerning librefs.

You can use the CONVERT procedure to convert BMDP, OSIRIS, and SPSS files to SAS files. See CONVERT Procedure: UNIX for more information.


The BMDP Engine


What Is the BMDP Engine?

The BMDP interface library engine enables you to read BMDP files from the BMDP statistical software application directly from a SAS program. The BMDP engine is a read-only engine. The following discussion assumes that you are familiar with the BMDP save file terminology.(footnote 1)

Note:   This engine is available for AIX, HP-UX, and Solaris.  [cautionend]


Syntax for Accessing BMDP Save Files

To read a BMDP save file, issue a LIBNAME statement that explicitly specifies the BMDP engine. In this case, the LIBNAME statement has the following form:

LIBNAME libref BMDP 'filename';

where:

libref

specifies a SAS libref.

filename

specifies a BMDP physical filename.

Note:   If the libref appears previously as a fileref, omit filename because SAS uses the physical filename that is associated with the fileref.  [cautionend]

This engine can read save files that are created only on UNIX.

Because a single physical file can contain multiple save files, 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 the files as MyLib.ABC and MyLib.DEF. All CONTENT types are treated the same. Even if member DEF has the value CONTENT=CORR, it is treated as if the value was 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, refer to the member name as _FIRST_. This reference is convenient if you do not know the CODE= value.


Example: BMDP Engine

Assume that the physical file mybmdp.dat contains the save file ABC. The following SAS code associates the libref mylib with the BMDP physical file and executes 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 writes the data for the first save file in the physical file:

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


The OSIRIS Engine


What Is the OSIRIS Engine?

The Inter-University Consortium for Political and Social Research (ICPSR) uses the OSIRIS file format for distribution of its data files. SAS provides the OSIRIS interface library engine to support the many users of the ICPSR data and to be compatible with PROC CONVERT.

With the OSIRIS engine, you can read OSIRIS data and dictionary files directly from a SAS program. The following discussion assumes that you are familiar with the OSIRIS file terminology and structure. If you are not, refer to the documentation provided by ICPSR.


Notes About the OSIRIS Data Dictionary Files

Because OSIRIS software does not run outside the z/OS environment, the layout of an OSIRIS data dictionary is consistent across operating environments. However, the OSIRIS engine is designed to accept a data dictionary from any other operating environment on which SAS runs. It is important that the dictionary and data files not be converted from EBCDIC to ASCII; the engine expects EBCDIC data.

The dictionary file should consist of fixed-length records of length 80. The data file should contain records that are large enough to hold the data that is described in the dictionary.


Syntax for Accessing an OSIRIS File

To read an OSIRIS file, issue a LIBNAME statement that explicitly specifies the OSIRIS engine. In this case, the syntax of the LIBNAME statement has the following form:

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

where:

libref

specifies a SAS libref.

'data-filename'

specifies the physical filename of the data file.

If the libref appears also as a fileref, omit data-filename.

DICT='dictionary-filename'

specifies the physical filename of the dictionary file. If dictionary-filename is an environment variable or a fileref, do not enclose it in quotation marks. The DICT= option is required.

OSIRIS data files do not have member names. Therefore, use whatever member name you want.

To use the same dictionary file with different data files, use a separate LIBNAME statement for each one.


Example: OSIRIS Engine

In the following example, the data file is /users/myid/osr/dat , and the dictionary file is /users/myid/osr/dic . The example associates the libref mylib with the OSIRIS files, and executes the CONTENTS and the PRINT procedures:

libname mylib osiris '/users/myid/osr/dat'
   dict='/users/myid/osr/dic';  
proc contents data=mylib._first_; 
run;  
proc print data=mylib._first_; 
run;


The SPSS Engine


What Is the SPSS Engine?

The SPSS engine is a read-only engine. With the SPSS interface library engine, you can read only SPSS export files. This engine does not read SPSS-X native files.


Syntax for Accessing an SPSS Export File

To read an SPSS export file, issue a LIBNAME statement that explicitly specifies the SPSS engine. In this case, the syntax of the LIBNAME statement has the following form:

LIBNAME libref SPSS 'filename';

where:

libref

specifies a SAS libref.

'filename'

specifies the physical filename.

Note:   If the libref appears also as a fileref, omit filename because SAS uses the physical filename that is associated with the fileref.  [cautionend]

Export files must be created by the SPSS EXPORT command and can originate from any operating environment. Export files must be transported to and from your operating environment in ASCII format. If they are transported in binary format, other operating environments will not be able to read them.

Because SPSS-X files do not have internal names, refer to them by any member name you like. A common extension for export files is .por, but this extension is not required.

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-missing) 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.


Reformatting SPSS Files

SAS cannot use an SPSS file that contains a variable with a numeric format that has a larger number of decimal places than the width of the entire variable. For example, if an SPSS file has a variable with a width of 17 and has 35 decimal places, SAS will return errors when you try to run a DATA step on the file or view it with the table viewer. To use the SPSS file with SAS, you have to 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 example 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 the number 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 with a DATA step or the table viewer. You have to reformat numeric variables that have a larger decimal value than their width before you can use a DATA step or the table viewer.   [cautionend]


Example: SPSS Engine

The following example associates the libref mylib with the physical file /users/myid/mydir/myspssx.por to execute the CONTENTS and PRINT procedures on the export file:

libname mylib spss '/users/myid/mydir/myspssx.por';
proc contents data=mylib._first_; 
proc print data=mylib._first_; 
run;

In the next example, the FILENAME statement associates the fileref mylib2 with the /users/myid/mydir/aspssx.por SPSS physical file, and the LIBNAME statement associates the libref with the SPSS engine. The PRINT procedure writes the data from the portable file.

filename mylib2 '/users/myid/mydir/aspssx.por'; 
libname mylib2 spss;
proc print data=mylib2._first_; 
run;


FOOTNOTE 1:   See the documentation provided by BMDP Statistical Solutions on the Web site for more information. [arrow]

Previous Page | Next Page | Top of Page