Skip to content. | Skip to navigation

Personal tools

A SAS User's Guide to Stata

This guide is intended to introduce a SAS user to Stata and to be a cheat sheet when writing Stata code.


Tools to transfer data between SAS and Stata

(all require that both SAS and Stata are able to be invoked on the same computer)

  • SAVASTATA:  SAS macro to save a SAS dataset as a Stata dataset.
  • SAVASAS:  Stata command to save a Stata dataset as a SAS dataset.
  • USESAS:  Stata command to use a SAS dataset while in Stata.
  • USESTATA:  See the example in the STATA WRAPPER page that shows you how to create a SAS dataset from a Stata dataset.
  • SAVAS (c-shell) script:  Invoked at a UNIX/Linux prompt makes Stata datafile copies of SAS datafiles or SAS datafile copies of Stata datafiles.
  • STATA_WRAPPER:  SAS macro to run Stata code from within SAS.
  • SASWRAPPER:  Stata command to run a SAS program from within Stata.


SAS macros inspired by Stata programs

  • CHAR2FMT:  SAS macro to encode character variables.
  • RUNQUIT:  SAS macro to stop SAS from processing more code when an error occurs without ending your SAS session.
  • ISID:  SAS macro to test if variable(s) uniquely identify each observation in a dataset.
  • MINIME:  SAS macro to reset variable lengths to minimize the SAS dataset.
  • WHICH:  Find out what SAS macro SAS will invoke.
  • REN_STEM:  SAS macro to rename variables.
  • TYPE:  SAS macro to print a text file to your SAS output window.


Stata programs

  • ADOEDIT:  Stata command to edit an ado-file in Stata's do-file editor
  • ETIME:  Stata command to keep track of elapsed time
  • IFWINS:  Stata command to subset dataset by if exp before subsetting by in range
  • LOOKFORIT:  Stata command to search variable names and variable labels for some string or strings
  • LOOKFOR_ALL:  Searches for variables/patterns in Stata data files (.dta)
  • LSTRFUN:  Modify long local macros that contain strings
  • MKPROFILE:  Stata command to create or edit your
  • NSPLIT:  Stata command to split numeric variables with integer values into new smaller numeric variables
  • RCD:  Recursively traverse directories and execute any command in or for each one of them


Tools to transfer data between SAS matrix catalog files and SAS datasets

These SAS macros use PROC IML and are a great way to migrate a SAS matrix catalog file between operating systems since SAS catalog files can only be opened in the operating system they were created on.

  • MAT2DAT:  SAS macro to create SAS datasets from a SAS matrix catalog file
  • DAT2MAT:  SAS macro to create a SAS matrix catalog file from SAS datasets


Note: Dan Blanchette wrote these commands and web pages, however please direct questions to Phil Bardsley as noted below.

Questions or comments? If you are affiliated with the Carolina Population Center, send them to Phil Bardsley.