|
|
||||||||||||||||||||||
SAVASTATA: Save SAS datasets as Stata datatsetsIf you want to use SAVASTATA, then feel free to download load it here: Download savastata.sas If you are not prompted to "Save To Disk", then right-click the link and choose "Save Link Target As..." Otherwise, you will need to save the web page to your computer. Make sure you save the savastata.sas file as a plain text file not an htm/html file.
The best way to download SAVASTATA is to use Stata's command net install to install usesas. The savastata.sas file will be saved in
whatever directory Stata saves downloaded files that begin with the letter "s". The Stata command
findfile will help you find the file
savastata.sas.
Why use SAVASTATA? Disclaimer: There is no warranty on this software either expressed or implied. This program is released under the terms and conditions of GNU General Public License. About SAVASTATA
Programmer: Dan Blanchette ()
Center for Entrepreneurship and Innovation Duke University's Fuqua School of Business Durham, NC USA Developed at The Carolina Population Center at The University of North Carolina at Chapel Hill Date: 20Oct2003 Last updated: 13Mar2009 Save the most recently created SAS dataset in the WORK library to a Stata dataset
%savastata( "directory to save Stata dataset",
options );
Dependency: SAVASTATA requires that you have a working copy of SAS and a working copy of Stata Intercooled, SE or MP on your computer to run successfully. If your SAS dataset is small enough SAVASTATA may work on Stata Small (Student Version). Description
SAVASTATA uses the most recently created dataset in the WORK directory, figures out how best to store the
data as a Stata dataset, keeps most date formats and other basic formats for numeric variables, checks for invalid Stata
variable names, if using or outputting to Stata 6: checks to see if long variable names need to be shortened, prints
them to the SAS log and shortens them, writes out the SAS dataset to an ASCII datafile, attempts to preserve all user-defined
formats for numeric variables, writes out Stata do-files, and submits them to Stata in batch mode in order to have Stata
read the data in and saves the data as a Stata dataset.
If your SAS dataset is using formats that are in a formats catalog, SAVASTATA will make an attempt to preserve them as value labels in Stata. Stata does not allow all the variations of user-defined formats that SAS offers. Restrictions of each version of Stata:
Options
How to use the SAVASTATA macro:
Using the SAVASTATA macro requires that you understand how to use the "%include" SAS statement
and that you know how to call a SAS macro.
%include "LOCATION AND NAME OF A FILE THAT CONTAINS SAS CODE";For example, if you have copied this file to "c:\SASmacros\", then you tell SAS about this macro by adding the following line to your SAS program: %include "c:\SASmacros\savastata.sas"; The include statement makes SAS aware of the SAVASTATA macro which is in the file savastata.sas. To use the macro you have to make a call to it. To do that you
add a line like the following to your SAS program:
%savastata(c:\mySASdir\, -old);The information inside the parentheses is passed on to the SAVASTATA macro. The first string of information is the location you want to save your SAS dataset as a Stata dataset. This is somewhat like a libname statement. The second string of information is the options you wish to pass on to the SAVASTATA macro. You can use as many options as you like or none at all. Examples
%include "C:\SASmacros\savastata.sas"; ** Include macro once in a SAS session and call it
* as many times as you like in that session. **;
data work.ToBeStata; ** This makes a copy of the SAS dataset in the in the WORK library. **;
set in.mySASfile;
run;
%savastata(c:\mydata\,); ** Saves the dataset in the c:\mydata\ directory if it does not
* already exist in that directory. **;
%savastata(c:\mydata\,-replace); ** Saves the dataset c:\mydata\, overwriting it if
* it already exists. **;
%savastata(c:\data\,-old); ** Saves the dataset as the previous version of Stata
* in c:\data\ directory **;
%savastata("c:\data\",-old -replace); ** Saves the dataset as the previous version of Stata
* in c:\data\ directory, overwriting it if it
* already exists. **;
%savastata(c:\data\,-intercooled); ** Saves the dataset as the Intercooled version of Stata
* in c:\data\ directory. This is only possible if
* your version of Stata is an SE edition. Starting with
* Stata 10 it only checks that your dataset has no more
* than 2,047 variables. **;
** This is a UNIX/Linux example: **;
%savastata(/project/data/,-old -intercooled); ** Saves the dataset as previous version of
* Stata Intercooled in the /project/data/
* directory **;
Setting up SAVASTATA
These are instructions to edit the
savastata.sas file.
NOTE: If you are setting up this macro on your computer for the first time, you can choose which version of Stata you are going to have SAVASTATA use. If you do not choose to set the following switches, SAVASTATA will figure out what version of Stata you are running for you. This may add a noticeable amount of time to processing so you may want to set these switches to the correct version of Stata. You can easily figure out what version of Stata you are using by looking at the top of your results window in Stata or by typing in the Stata command about at the Stata command line. One advantage of leaving SAVASTATA to figure out what version of Stata is being used is that when you upgrade your version of Stata you will not have to update SAVASTATA.
%** Need to set all if you set any. **;
%let u_ver=0.0; %** version of Stata that is being used. decimal values are okay. *;
%* set this if you do not want Stata to be run just figure out what *;
%* version of Stata you are using. *;
%let s_ver=0.0; %** version of Stata that data will be saved as. *;
%* set this only if you set the u_ver variable. *;
%* old option will change this if used **;
%let u_SEver=0; %** 1 if SE/MP version of Stata that is being used. *;
%let s_SEver=0; %** 1 if SE/MP version of Stata that data will be saved as. *;
%* intercooled option will change this if used **;
NOTE: If you are running SAVASTATA on the UNIX/Linux platforms then you need to be able to start a Stata batch job by: $ stata -b do mydofile.doIf not then change the setting of the ustata macro variable. %let ustata=stata; /* This may work: %let ustata=/usr/local/stata/stata; */ If you are running SAVASTATA on the Windows platform, you may need set the location of the Stata executable file: wstata.exe in the SAVASTATA SAS macro. If
you do not know where your wstata.exe is located, find your Stata short-cut icon, right
click on it, choose "properties", and look in the "target" field. This will show you where
the wstata.exe is located on your hard drive.
Change what is inside the parentheses to the location of your wstata.exe file.
%let wstata=%nrstr(c:\Stata\wstata.exe); ** This may work. **; Back to Main Page Questions or comments? Send them to Dan Blanchette () |
|||||||||||||||||||||||