FILETYPE=SAS

 

Using SAS Data in SAS-Callable SUDAAN

SAS-Callable SUDAAN can read any data set that SAS itself can read.  Simply create a SAS libname statement that points to the directory where your data is located, and optionally provide a SAS engine name ahead of your SUDAAN program.  You then specify any input data set on the PROC statement using the libname.memname syntax.

 

Follow the same requirements to specify a SAS data set on your SUDAAN OUTPUT statement.  Note that SAS-callable SUDAAN cannot directly access the SAS Output Data System (ODS).

See Section 2.6.5 for examples of this syntax.

 

 

Using SAS Data in Standalone SUDAAN: File Type SASXPORT

Standalone SUDAAN cannot directly read or write most SAS data sets.  However, it can read and write data in the SASXPORT format, which is in the public domain.  Note that the SASXPORT file type is the XPORT file type supported by SAS, which was adopted by the United States Food and Drug Administration (FDA) as a standard for data submissions.  The structure of this file type is fully documented on SAS Institute’s Web site.

 

Use FILETYPE = SASXPORT on the PROC statement to specify that your input data set is in the SASXPORT format, and use FILETYPE = SASXPORT on the OUTPUT statement to specify that your output data set is in this format. 

 

NOTE

SAS has two export file types:  XPORT (older) and CPORT.  SUDAAN can only read the XPORT format, which is in the public domain.  The CPORT format is a SAS proprietary format to which standalone SUDAAN does not have access. 

 

When you use SASXPORT files for input to standalone SUDAAN, you may also supply a SAS format catalog in XPORT format using the LEVFILE option on the PROC statement.  You then use the FORMAT statement to associate SAS formats with variables.  Use the XPORT engine on the SAS libname statement associated with the data set you wish to create.  Use the default SAS engine on the SAS libname statement associated with the data set you wish to convert to XPORT format.

 

The following examples illustrate this process.

 

EXAMPLE

These SAS statements will create a data set TERATA.XPT in XPORT format.  Execute this code in SAS.

 

libname out xport "c:\sas8files\terata.xpt";

libname in "c:\sas8files";

data out.terata;

set in.terata;

run;

 

 

If you have a format library, you can create a format catalog, also in XPORT format.  Follow the steps outlined next.

 

EXAMPLE

These SAS statements create a SAS format catalog and then convert it to XPORT file type.  Execute this code in SAS.

 

libname library "c:\sas8files";

libname out "c:\sas8files";

proc format library=library cntlout=out.fmtlib;

run;

 

libname xout xport "c:\sas8files\teratalev.xpt";

data xout.teratalev;

set out.fmtlib;

run;

 

You can use the files created in the examples above in SUDAAN.  Follow the steps in the next example:

 

EXAMPLE

This example illustrates the use of the SASXPORT file type in PROC LOGISTIC.  Execute this code in standalone SUDAAN.

 

PROC LOGISTIC DATA="c:\sas8files\terata.xpt"

              FILETYPE=SASXPORT

              LEVFILE="c:\sas8files\teratalev.xpt";

FORMAT dose_5 dose_5.;

...Additional logistic statements ...

 

You can also use the SASXPORT file format when creating output data sets in standalone SUDAAN.  Specify FILETYPE=SASXPORT on the OUTPUT statement.  In addition, you can use the LEVFILE=filename to create a SAS FORMAT catalog in XPORT format, for later use in SAS or other programs.

 

The SASXPORT file format does not support long variable names and labels that are now available in SAS and SUDAAN.  Specifically, within SAS you cannot write variables with long names and/or labels to an XPORT file, nor can SUDAAN directly create an XPORT file with the long names and/or labels.  To overcome this limitation when SUDAAN creates an SASXPORT file, SUDAAN truncates long variable names and labels in a unique way so that different variables always have distinct names up to the limit of eight characters.  SUDAAN will simultaneously create a second file, also in SASXPORT format, that links long and short forms of variable names and labels.  This means that SAS users can easily import their labels from SUDAAN into SAS along with their data.

 

To support these changes, two options are available on both the PROC and OUTPUT statements when FILETYPE=SASXPORT is used:  NAMEFILE and LEVFILE.  (See Section 4.2 of the SUDAAN 10 Language Manual for more information on these options.) 

 

To illustrate this, consider the following example which creates a file in SASXPORT format, along with a SAS format catalog in XPORT format.  We assume that the ASCII data set mydata contains a variable named SEX, and that the accompanying .LEV file contains the labels for the levels of this variable. 

 

EXAMPLE

These statements convert a data set of type ASCII to a data set of type SASXPORT.  They also convert the associated value labels to a SAS format catalog in XPORT format.  Execute these statements in standalone SUDAAN.

 

PROC LOGISTIC DATA=”c:\datfiles\mydata” FILETYPE=ASCII NOPRINT;

… analysis statements…

OUTPUT / FILENAME=”c:\datfiles\lgpred” PREDICTED=ALL

         FILETYPE=SASXPORT REPLACE

         LEVFILE=”c:\datfiles\predlev”;

 

We now show how to use these files in SAS.

 

EXAMPLE

These SAS statements import the format catalog created by SUDAAN, as well as the data set created in the example above, and uses them in an analysis.  Execute these statements in SAS.

 

libname out “c:\sasfiles”;

 

libname xin xport “c:\datfiles\predlev.stx”;

 

data predlev;

set xin.predlev;

run;

 

proc format cntlin=predlev;

run;

 

 

libname xxin xport “c:\datfiles\lgpred”;

 

data lgpred;

set xxin.lgpred;

run;

 

proc print data=lgpred(obs=25);

run;

 

There are two common extensions for files in SASXPORT format:  ‘.STX’ and ‘.XPT’.  To make sure SUDAAN reads or creates the file with the extension you intend, include it in the file specification in any of the following parameters on the PROC statement.

 

DATA

PSUDATA

REPDATA

NAMEFILE

LEVFILE

 

Further, include the appropriate extension in the file specifications in the following parameters on the OUTPUT statement.

 

FILENAME

NAMEFILE

LEVFILE

 

If you do not specify an extension, SUDAAN will use the extension ‘.STX’ by default on input and output statements. 

 

On input, if SUDAAN supplies ‘.STX’ and does not find an input data set by the given name, it will try supplying the extension ‘.XPT’ before giving up.

 

 

FORMAT Statements in the SUDAAN Program File

You can include FORMAT (RFORMAT) statements among your SUDAAN procedure statements directly in your SUDAAN program file when the input dataset is of type SASXPORT (SAS).  This allows you to

 

 

 

Standalone SUDAAN will recognize the following FORMAT statement:

 

FORMAT variable(s) format_name.  ;

 

In SAS-callable SUDAAN you must use

 

RFORMAT variable(s) format_name.  ;

 

Standalone SUDAAN will look for a format in the format file supplied in the LEVFILE= parameter on the PROC statement under the specified format_name.  If SUDAAN finds that format_name, it uses the text for the one or more listed variables’ labels in PRINT tables and OUTPUT file documentation.

 

If a FORMAT statement contains a format_name that SUDAAN cannot find in the format file, or if the format file itself is not provided, SUDAAN does not produce any warning/error message.  Instead, SUDAAN uses the information that is next in priority, as explained in the next section.

 

SAS-callable SUDAAN obtains the format from SAS.  It may be created earlier in a FORMAT procedure, or it may be located in a SAS Format Catalog.

 

SUDAAN can handle only simple FORMAT statements.  A single FORMAT statement can list one or several variables but can name only a single format.  For multiple formats, you must include multiple FORMAT statements in your SUDAAN procedure statements—one for each format.

 

EXAMPLE

The following are valid FORMAT statements in SUDAAN:

 

FORMAT RACE RACEFMT.;

FORMAT Q1 Q2 Q3 Q4 Q5 YESNO.;

 

 

Order of Precedence for SAS Formats and Other Labels

SUDAAN’s order of precedence for choosing the text label to use for levels of a categorical variable is