UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS FAQ
How do I convert SAS files with formats to Stata?

You can use Stat/Transfer to copy SAS files (with formats) into Stata data (.dta) files.  It requires a small amount of extra work to do this, as described below.

Step 1. Make a copy of your format library as a regular SAS data file

Say that you have a SAS data file on your PC in a directory called c:\carsdata and and your data file and format library are both located in that directory.  Suppose that the file is called auto.sd2 and your permanent format library is called formats.sc2 (the format library is always called formats.sc2).  Stat/Transfer does not understand how to read the formats.sc2 file, but SAS can create a regular data file that Stat/Transfer can understand.  The sample program below shows how to do this.  In this program, only change the directory (i.e., c:\carsdata ) to be the directory where your format file is located.

LIBNAME LIBRARY "c:\carsdata" ;
PROC FORMAT LIBRARY=LIBRARY CNTLOUT=LIBRARY.SAS_FMTS ;
RUN;

When you have run the above program, it will create a file called sas_fmts.sd2 in the c:\carsdata directory.   Stat/Transfer can read this file to convert your formats from SAS to Stata, so now, you are ready to transfer your SAS data file and formats to Stata using Stat/Transfer.  

Step 2. Copy the file Using Stat/Transfer

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

wpe98.jpg (27675 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 Read user formats from a SAS datafile.

wpe97.jpg (42436 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.dta that has Stata formats associated with the variables.

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.