Using SAS Data in Standalone SUDAAN
Using SAS data in Standalone SUDAAN and SUDAAN data in SAS
1: How can I read my SAS data in Standalone SUDAAN?
2: Is there any way to write my Standalone SUDAAN output in a format easily read by SAS?
3: I created a SAS export data set, but SUDAAN is telling me it isn’t a valid XPORT data set.
4: Can I use long variable names and labels with SASXPORT data?
1: How can I read my SAS data in Standalone SUDAAN?
To read SAS data within Standalone SUDAAN you must create a SAS XPORT data set. This contains exactly the same information as the original data set, just stored in a different way. Here are the steps:
Sample SAS code for creating a dataset in XPORT format:
Libname out "c:\sasfiles\terata.xpt";
libname in "c:\sasfiles";
data out.terata;
set in.terata;
run;
This will create a data set TERATAXPT in XPORT format.
If you have a format library, you can create a format catalog, also in XPORT format as the following sample SAS code shows:
libname library "c:\sasfiles";
libname out "c:\sasfiles";
proc format library=library cntlout=out.fmtlib;
run;
libname xout xport "c:\sasfiles\teratalev.xpt";
data xout.teratalev;
set out.fmtlib;
run;
You can then use these files in SUDAAN as the following example SUDAAN code shows:
proc logistic filename="c:\sasfiles\terata.xpt" filetype=sasxport levfile="c:\sasfiles\teratalev.xpt" format dose_5 dose_5.;
...Additional logistic statements ...
2: Is there any way to write my Standalone SUDAAN output in a format easily read by SAS?
Beginning with Release 7.5.4 for PCs and Release 7.5.5 for Solaris, you can write your Standalone SUDAAN output in a SASXPORT data set, saving all of the format labels in a companion SAS FORMAT CATALOG in SASXPORT format, and then import these into SAS for further analysis. The following example shows how to do this in Standalone SUDAAN:
proc logistic data="c:\sasfiles\terata" filetype=sasxport levfile="c:\sasfiles\terlev.xpt" noprint;
nest _one_ dam;
weight _one_;
subgroup dose_5;
format dose_5 dose_5.;
levels 5;
reflevel dose_5=1;
model dead=dose_5;
output / predicted=all filetype=sasxport filename="c:\sasfiles\terpred" levfile="c:\sasfiles\terprlev" replace;
The following set of SAS statements imports the format catalogue, format created by SUDAAN, as well as the output data set, terpred,and uses them in an analysis.
libname xin xport "c:\sasfiles\terprlev.stx";
libname out "c:\sasfiles";
data out.terprlev;
set xin1.terprlev;
proc format cntlin=out.terprlev;
run;
libname xdin xport "c:\sasfiles\terpred.stx";
proc descript data=xdin.terpred filetype=sasxport design=wr;
nest _one_ dam;
weight _one_;
var expected;
print nsum wsum mean semean;
run;
3: I created a SAS export data set, but SUDAAN is telling me it isn’t a valid XPORT data set.
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 we do not have access. Are you sure you are using the XPORT engine to create the output file? The following sample SAS code shows how to convert a SAS dataset to XPORT format:
libname out xport "c:\sasfiles\testdat.xpt";
libname in "c:\sasfiles";
data out.testdat;
set in.testdat;
4: Can I use long variable names and labels with SASXPORT data?
Beginning with Release 7.5.4 of standalone SUDAAN for PCs and release 7.5.5 of Standalone SUDAAN for Sun/Solaris, SUDAAN can directly read data files created by SAS in XPORT format, and can also write files in the SAS XPORT format. For both reading and writing these files simply use "FILETYPE=SASXPORT" on the PROC or OUTPUT statements. Note that the SASXPORT file type is the XPORT file type supported by SAS, which has been recently adopted by the FDA as a standard for data submissions. The structure of this file type is fully documented at SAS Institute's web site. This is an important new feature for users of Standalone SUDAAN who wish to use data from SAS or to do further analysis of SUDAAN results within SAS, since SAS no longer exports version 6.04 SAS data sets.
The SAS XPORT file format does not support the longer variable names and labels that are available in SAS beginning with Version 7. Within SAS you cannot write variables with long names and/or labels to an XPORT file. However in SUDAAN, you can do this since SUDAAN automatically creates a second file, also in XPORT format which links long and short forms of variable names and labels. On output to a 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 8 characters. Whenever there is any truncation, SUDAAN saves a separate data set, also in SASXPORT format, with records whose data link old and new variable names and labels. In addition, whether or not there are any long variable names or labels, SUDAAN takes preserves any labels associated with the variables in a separate SASXPORT file. This file has the same structure as a SAS format catalog which has been saved in XPORT format. This means that SAS users can easily import their labels from SUDAAN into SAS along with their data.
To support these changes, two new options are now available on both the PROC and OUTPUT statements when FILETYPE=SASXPORT is used:
| NAMEFILE=filename | |
|
On the PROC statement use this parameter to specify the name of a file containing records associating long variable names and labels with their shortened versions on an input file in SASXPORT format. If this parameter is not supplied, SUDAAN will look for a file named . If SUDAAN cannot find a name file, whether the name is supplied explicitly or by default, or if the (long) variables used within the SUDAAN program are not on the given name file, then SUDAAN will not recognize them when reading the main data file in SASXPORT format. On the OUTPUT statement use this parameter to specify the name of a file in SASXPORT format to contain any records associating long variable names and labels with their shortened versions on the main output file. If this parameter is not supplied, and there are one or more variable names or labels which have to be truncated, SUDAAN will use the name NAMEFILE.STX. Note, however, that in no case will SUDAAN overwrite a file already using the specified filename unless the REPLACE option is present on the OUTPUT statement. |
|
| LEVFILE=filename | |
|
On the PROC statement use this parameter to specify the name of a file containing records with SAS-style format information. If this parameter is not supplied, SUDAAN will look for a file named LEVFILE.STX. If SUDAAN cannot find a level file, whether the name is supplied explicitly or by default, then SUDAAN will not be able to use formats named on FORMAT statements within your SUDAAN program. On the OUTPUT statement use this parameter to specify the name of a file in SASXPORT format to contain SAS-style formats to be associated with variables on the main data set. If this parameter is not supplied, and there are one or more variables with associated level labels, SUDAAN will use the name LEVFILE.STX. Note, however, that in no case will SUDAAN overwrite a file already using the specified filename unless the REPLACE option is present on the OUTPUT statement. SUDAAN will create a name for each format which is at most 8 characters in length, contains only '_', and alphanumeric characters, and does not begin with a numeric digit. This name will be as close to the name of the variable as possible. |
|
| There are two common extensions for files in SAS XPORT 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 |
|
| and include it 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 on output. 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.