Stata 15 help for import_sasxport

[D] import sasxport -- Import and export datasets in SAS XPORT format

Syntax

Import SAS XPORT Transport file into Stata

import sasxport filename [, import_options]

Describe contents of SAS XPORT Transport file

import sasxport filename , describe [member(mbrname)]

Export data in memory to a SAS XPORT Transport file

export sasxport filename [if] [in] [, export_options]

export sasxport varlist using filename [if] [in] [, export_options]

import_options Description ------------------------------------------------------------------------- Main clear replace data in memory novallabels ignore accompanying formats.xpf file if it exists member(mbrname) member to use; seldom used -------------------------------------------------------------------------

export_options Description ------------------------------------------------------------------------- Main rename rename variables and value labels to meet SAS XPORT restrictions replace overwrite files if they already exist vallabfile(xpf) save value labels in formats.xpf vallabfile(sascode) save value labels in SAS command file vallabfile(both) save value labels in formats.xpf and in a SAS command file vallabfile(none) do not save value labels -------------------------------------------------------------------------

Menu

import sasxport

File > Import > SAS XPORT

export sasxport

File > Export > SAS XPORT

Description

import sasxport and export sasxport convert datasets from and to SAS XPORT Transport format. The U.S. Food and Drug Administration uses SAS XPORT Transport format as the format for datasets submitted with new drug and new device applications (NDAs).

To save the data in memory as a SAS XPORT Transport file, type

. export sasxport filename

although sometimes you will want to type

. export sasxport filename, rename

It never hurts to specify the rename option. In any case, Stata will create filename.xpt as an XPORT file containing the data and, if needed, will also create formats.xpf -- an additional XPORT file -- containing the value-label definitions. These files can be easily read into SAS.

To read a SAS XPORT Transport file into Stata, type

. import sasxport filename

Stata will read into memory the XPORT file filename.xpt containing the data and, if available, will also read the value-label definitions stored in formats.xpf or FORMATS.xpf.

import sasxport, describe describes the contents of a SAS XPORT Transport file. The display is similar to that produced by describe. To describe a SAS XPORT Transport file, type

. import sasxport filename, describe

If filename is specified without an extension, .xpt is assumed.

Options for import sasxport

+------+ ----+ Main +-------------------------------------------------------------

clear permits the data to be loaded, even if there is a dataset already in memory and even if that dataset has changed since the data were last saved.

novallabels specifies that value-label definitions stored in formats.xpf or FORMATS.xpf not be looked for or loaded. By default, if variables are labeled in filename.xpt, then import sasxport looks for formats.xpf to obtain and load the value-label definitions. If the file is not found, Stata looks for FORMATS.xpf. If that file is not found, a warning message is issued.

import sasxport can use only a formats.xpf or FORMATS.xpf file to obtain value-label definitions. import sasxport cannot understand value-label definitions from a SAS command file.

member(mbrname) is a rarely specified option indicating which member of the .xpt file is to be loaded. It is not used much anymore, but the original XPORT definition allowed multiple datasets to be placed in one file. The member() option allows you to read these old files. You can obtain a list of member names using import sasxport, describe. If member() is not specified -- and it usually is not -- import sasxport reads the first (and usually only) member.

Option for import sasxport, describe

+------+ ----+ Main +-------------------------------------------------------------

member(mbrname) is a rarely specified option indicating which member of the .xpt file is to be described. See the description of the member() option for import sasxport directly above. If member() is not specified, all members are described, one after the other. It is rare for an XPORT file to have more than one member.

Options for export sasxport

+------+ ----+ Main +-------------------------------------------------------------

rename specifies that export sasxport may rename variables and value labels to attempt to meet the SAS XPORT restrictions, which are that names be no more than eight bytes long and that there be no distinction between uppercase and lowercase letters. Note that rename does not remove characters beyond the normal ASCII range, such as most Unicode characters and all extended ASCII characters. SAS may or may not support such characters in variable labels and value labels.

We recommend specifying the rename option. If this option is specified, any name violating the restrictions is changed to a different but related name in the file. The name changes are listed. The new names are used only in the file; the names of the variables and value labels in memory remain unchanged.

If rename is not specified and one or more names violate the XPORT restrictions, an error message will be issued and no file will be saved. The alternative to the rename option is that you can rename variables yourself with the rename command:

. rename mylongvariablename myname

See [D] rename. Renaming value labels yourself is more difficult. The easiest way to rename value labels is to use label save, edit the resulting file to change the name, execute the file by using do, and reassign the new value label to the appropriate variables by using label values:

. label save mylongvaluelabel using myfile.do . doedit myfile.do (change mylongvaluelabel to, say, mlvlab) . do myfile.do . label values myvar mlvlab

See [D] label and [R] do for more information about renaming value labels.

replace permits export sasxport to overwrite existing filename.xpt, formats.xpf, and filename.sas files.

vallabfile(xpf|sascode|both|none) specifies whether and how value labels are to be stored. SAS XPORT Transport files do not really have value labels. Value-label definitions can be preserved in one of two ways:

1. In an additional SAS XPORT Transport file whose data contain the value-label definitions

2. In a SAS command file that will create the value labels

export sasxport can create either or both of these files.

vallabfile(xpf), the default, specifies that value labels be written into a separate SAS XPORT Transport file named formats.xpf. Thus export sasxport creates two files: filename.xpt, containing the data, and formats.xpf, containing the value labels. No formats.xpf file is created if there are no value labels.

SAS users can easily use the resulting .xpt and .xpf XPORT files. See http://www.sas.com/govedu/fda/macro.html and click on the FDA Submission Standards tab and then click on the Processing Data Sets Code tab that appears below the "FDA and SAS Technology" text for SAS-provided macros for reading the XPORT files. The SAS macro fromexp() reads the XPORT files into SAS. The SAS macro toexp() creates XPORT files. When obtaining the macros, remember to save the macros at SAS's webpage as a plain-text file and to remove the examples at the bottom.

If the SAS macro file is saved as C:\project\macros.mac and the files mydat.xpt and formats.xpf created by export sasxport are in C:\project\, the following SAS commands would create the corresponding SAS dataset and format library and list the data:

+------------------- SAS commands --------------------+ | %include "C:\project\macros.mac" ; | | %fromexp(C:\project, C:\project) ; | | libname library 'C:\project' ; | | data _null_ ; set library.mydat ; put _all_ ; run ; | | proc print data = library.mydat ; | | quit ; | +-----------------------------------------------------+

vallabfile(sascode) specifies that the value labels be written into a SAS command file, filename.sas, containing SAS proc format and related commands. Thus export sasxport creates two files: filename.xpt, containing the data, and filename.sas, containing the value labels. SAS users may wish to edit the resulting filename.sas file to change the "libname datapath" and "libname xptfile xport" lines at the top to correspond to the location that they desire. export sasxport sets the location to the current working directory at the time export sasxport was issued. No .sas file will be created if there are no value labels.

vallabfile(both) specifies that both the actions described above be taken and that three files be created: filename.xpt, containing the data; formats.xpf, containing the value labels in XPORT format; and filename.sas, containing the value labels in SAS command-file format.

vallabfile(none) specifies that value-label definitions not be saved. Only one file is created: filename.xpt, which contains the data.

Remarks

All users, of course, may use these commands to transfer data between SAS and Stata, but there are limitations in the SAS XPORT Transport format, such as the eight-character limit on the names of variables (specifying export sasxport's rename option works around that). For a complete listing of limitations and issues concerning the SAS XPORT Transport format, and an explanation of how export sasxport and import sasxport work around these limitations, see Technical appendix in [D] import sasxport.

Remarks are presented under the following headings:

Saving XPORT files for transferring to SAS Determining contents of XPORT files received from SAS Using XPORT files received from SAS

Saving XPORT files for transferring to SAS

To save the current dataset in mydata.xpt and the value labels in formats.xpf, type

. export sasxport mydata

To save the data as above but automatically handle renaming variable names and value labels that are too long or are case sensitive, type

. export sasxport mydata, rename

To allow the replacement of any preexisting files, type

. export sasxport mydata, rename replace

To save the current dataset in mydata.xpt and the value labels in SAS command file mydata.sas and to automatically handle renaming variable and value-label names:

. export sasxport mydata, rename vallab(sas)

To save the data as above but save the value labels in both formats.xpf and mydata.sas, type

. export sasxport mydata, rename vallab(both)

To not save the value labels at all, thus creating only mydata.xpt, type

. export sasxport mydata, rename vallab(none)

Determining contents of XPORT files received from SAS

To determine the contents of testdata.xpt, you might type

. import sasxport testdata, describe

Using XPORT files received from SAS

To read data from testdata.xpt and obtain value labels from formats.xpf (or FORMATS.xpf), if the file exists, you would type

. import sasxport testdata

To read the data as above and discard any data in memory, type

. import sasxport testdata, clear

Stored results

import sasxport, describe stores the following in r():

Scalars r(N) number of observations r(k) number of variables r(size) size of data r(n_members) number of members

Macros r(members) names of members


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index