Previous Page | Next Page

File Format-Specific Reference for the IMPORT and EXPORT Procedures

Stata DTA Files


DTA Files Essentials

All versions of Stata under Microsoft Windows are supported. Stata files have a .dta file extension.

See Example 1: EXPORT a SAS Data Set to a Stata File on a Local System.


DTA Data Types

FILES

Import of all Stata versions under Microsoft Windows and UNIX is supported. Export of Stata version 8 and later is supported.

MISSING VALUES

Stata supports missing values. SAS missing values are written as Stata missing values.

VARIABLE NAMES

When using importing, Stata variable names can be up to 32 characters in length. The first character in a variable name can be any lowercase letter (a-z) or uppercase letter (A-Z), or an underscore ( _ ). Subsequent characters can be any of these characters, plus numerals (0-9). No other characters are permitted. Stata reserves these 19 words, which are not allowed to stand alone as variable names:

_all long _N
in _skip _weight
_pred _cons float
_b _n pi
int using with
_rc double if
_coef

If the program encounters any of these reserved words as variable names, it appends an underscore to the variable name to distinguish it from the reserved word. For example, _N becomes _N_ .

When exporting, variable names greater than 32 characters are truncated. The first character in a variable name can be any lowercase letter (a-z) or uppercase letter (A-Z), or an underscore ( _ ). Subsequent characters can be any of these characters, plus numerals (0-9). No other characters are permitted. Invalid characters are converted to underscores ( _ ).

VARIABLE LABELS

Stata supports variable labels when using the IMPORT procedure. When exporting, if the variable name is not a valid Stata name and there is no label, the EXPORT procedure writes the variable name as the label.

VALUE LABELS

Stata stores value labels within the data file. The value labels are converted to format library entries as they are read with the IMPORT procedure. The name of the format includes its associated variable name modified to meet the requirements of format names. The name of the format is also associated with a variable in the SAS data set. You can use FMTLIB=libref.format-catalog: statement to save the formats catalog under a specified SAS library.

When writing SAS data to a Stata file, the EXPORT procedure saves the value labels that are associated with the variables. The procedure uses the formats that are associated with the variables to retrieve the value entries. You can use the FMTLIB=libref.format-catalog statement to tell SAS where to locate the formats catalog.

Restriction: Numeric formats only.
DATA TYPES

Stata supports numeric field types that map directly to SAS numeric fields.

Stata date variables become numerics with a date format.

When writing SAS data to a Stata file, the EXPORT procedure converts data into variable type double. A SAS date format becomes a Stata date variable.


Importing and Exporting Data in Stata Files

PC Files Server (DBMS=PCFS)

This IMPORT|EXPORT method uses the client/server model to access data in Stata files on Microsoft Windows from Linux, UNIX, or Microsoft Windows 64-bit operating environments. This method requires running the PC Files Server on Microsoft Windows.

Requirement: A filename with a .dta extension is required.

IMPORT and EXPORT Procedures Supported Syntax

FMTLIB=libref.format-catalog

When importing a Stata file, SAS saves value labels to the specified SAS format catalog. When exporting a SAS data set to a Stata file, SAS uses formats that are associated with the variables to retrieve the value entries.


Example 1: EXPORT a SAS Data Set to a Stata File on a Local System

This example exports the SAS data set SDF.CUSTOMER, to the Stata file, CUSTOMER.DTA, on a local system.

LIBNAME SDF "&sasdir";
PROC EXPORT DATA=SDF.CUSTOMER
            FILE="&tmpdir.customer.dta"
            DBMS=STATA REPLACE;
RUN;


Example 2: IMPORT a SAS Data Set from a Stata File on a Local System

This example imports the SAS data set, WORK.CUSTOMER, from the Stata file, CUSTOMER.DTA, on a local system.

PROC IMPORT OUT=WORK.CUSTOMER
            FILE="&tmpdir.customer.dta"
            DBMS=STATA REPLACE;
RUN;


Example 3: EXPORT a SAS Data Set on UNIX to a Stata File on Microsoft Windows

This example exports a SAS data set named SDF.CUSTOMER to a Stata file named CUSTOMER.DTA. Note that SAS is running on the UNIX operating platform. The Stata file is loaded on Microsoft Windows where PC Files Server is running.

LIBNAME SDF "&sasdir";
PROC EXPORT DATA=SDF.CUSTOMER
            FILE="&tmpdir.customer.dta"
            DBMS=PCFS REPLACE;
   SERVER="&server";
  RUN;


Example 4: IMPORT Data from a Stata File on Microsoft Windows to a SAS Data Set on UNIX

This example imports data from a Stata file named CUSTOMER.DTA to a SAS data set named WORK.CUSTOMER. Note that SAS is running on a UNIX platform. The Stata file is located on Microsoft Windows where PC Files Server is running.

PROC IMPORT OUT= WORK.CUSTOMER
            FILE="&tmpdir.customer.dta"
            DBMS=PCFS REPLACE;
  SERVER="&server";
RUN;

Previous Page | Next Page | Top of Page