[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: SAS to Stata

From   Dan Blanchette <[email protected]>
To   [email protected]
Subject   Re: st: SAS to Stata
Date   Tue, 19 Jan 2010 11:37:39 -0500 (EST)

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"

data new;
 set (keep= stores);
  if stores in(1:5);
  cstores= strip(put(stores,8.0));
  format cstores $store_f.;

proc print;

** 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;

proc print work.myformats;

data myformats;
 set myformats;
 type= "N";

** Overwrite the SAS formats catalog in WORK with the SAS data set : **;
proc format library= work.formats cntlin= myformats;

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.;

proc print data= new;

proc contents data= new;


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.


*   For searches and help try:

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