UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata FAQ: How do I convert a Stata file
with value labels to become SAS files with formats?

You can use Stat/Transfer to convert Stata files with value labels to become SAS files with formats.  It requires a small amount of extra work to do this, as described below.  For this example, suppose that we have a file called auto.dta and it is stored in c:\carsdata .

Step 1. Convert the Stata file to SAS using Stat/Transfer

Start up Stat/Transfer. As you see below, on the first screen we picked Stata Version 6 as the input file type, and c:\carsdata\auto.dta as the file to transfer.  For the output file we have chosen SAS For Windows/OS2 and we accepted the default name for the output file, c:\carsdata\auto.sd2

wpe99.jpg (27618 bytes)

Once you have filled out the screen above, click the Options(1) tab and you will see a screen like the one below.  Check the box labeled Write a Proc Format program. We will use this program in Step 2 below.

wpe9A.jpg (42125 bytes)

Now, click the Transfer tab to return to the transfer screen, and on then click the box labeled Transfer to execute the transfer.  In our example, this creates a file called auto.sd2 and a program called c:\autodata\auto.sas that is able to create a format library associated with auto2.dta .

Step 2. Make your SAS format library

Stat/Transfer does not know how to directly create SAS format libraries, but it does know how to write a SAS program that can, in turn, create a your SAS format library for you.  By checking the box Write a Proc Format Program you asked Stat/Transfer to write such a program for you.  The program that it created in our example is shown below.  You don't need to change this program in any way.  Just load this program into SAS, and run it, and it will create a format library for your SAS data file.

libname library 'c:\carsdata\' ;

proc format library = library ;
   value FOREIGN
      0='domestic' 
      1='foreign';

proc datasets library = library ;
modify auto;
   format   FOREIGN FOREIGN.;
quit;

When you have run the above program, it will create a file called c:\carsdata\formats.sc2.

Web notes


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.