File Format-Specific Reference for the IMPORT and EXPORT Procedures |
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.
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. |
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. |
|
- 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.
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;
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;
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;
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;
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.