Hello Hillel,
I'm the author of -usesas-. Since Stata does not allow
value labels to be associated to string variables, there
is no way to preserve SAS's character formats in a Stata
string variable.
If your character variables in SAS actually have numeric
values with formats associated with them, then you can
convert the character variables to numeric variables
and also convert the character formats to numeric and
then associate the new numeric formats to the new numeric
variables. Simply creating a numeric variable from a
character variable will not also automatically change over
the format for the new numeric variable.
This is example SAS code that does this:
*******************************************************;
proc format;
value $store_f
"1"= "one store"
"2"= "two stores"
"3"= "three stores"
"4"= "four stores"
"5"= "five stores"
;;
run;
data new;
set sashelp.shoes (keep= stores);
if stores in(1:5);
cstores= strip(put(stores,8.0));
format cstores $store_f.;
run;
proc print work.new;
run;
** Create a SAS data set from the SAS formats catalog:
* The defualt location and name of the catalog file that
* stores SAS formats is: work.formats **;
proc format library= work.formats cntlout= myformats;
run;
proc print work.myformats;
run;
data myformats;
set myformats;
type= "N";
run;
** Overwrite the SAS formats catalog in WORK with the SAS data set : **;
proc format library= work.formats cntlin= myformats;
run;
data new;
set new;
** Create a numeric variable from a character variable:
** Non-numeric data will become missing data in the new numeric variable. **;
if _n_ = 1 then cstores= "d";
nstores= input(cstores,8.0);
format nstores store_f.;
run;
proc print data= new;
run;
proc contents data= new;
run;
*******************************************************;
Let me know if you have any more Qs,
Dan Blanchette
Research Associate
Center for Entrepreneurship and Innovation
Duke University's Fuqua School of Business
[email protected]
Date: Sun, 17 Jan 2010 15:47:43 -0500
From: Hillel Alpert <[email protected]>
Subject: st: SAS to Stata
Dear Stata Users,
I assume this is not at all a new question. We have a SAS file (for Windows) that contains string variables with value labels that are identified in an accompanying formats file. I find that the usesas command and Stat Transfer will copy the data to Stata but not the value labels. Is another utility or function within Stata available that can readily import SAS data with value labels associated with string variables, without having to edit format files from within SAS? Alternatively, is a data conversion program available that can change SAS string variables which are numbers to integer variables before using Stat Transfer to copy the data so that the value labels can be properly imported as well? I think this would be a good feature to find in Stat Transfer.
Hillel
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/