There are government data files available from this CDC web site, but they are in a weird SAS format.

How can I convert them into XML/CSV, i.e. something much simpler that can be read by scripts, etc?


StatTransfer will convert SAS files to a variety of formats and it includes options to filter variables or observations, customize the delimiter, and change variable storage formats during the transfer.

AM will also covert data, but it's less powerful/flexible. AM is freeware and written for Windows.

| improve this answer | |

You can do this with R-cran, if you have SAS xpt files. Use the foreign and hmisc packages.

xpt = sasxport.get("xpt/DEMO.xpt")
write.csv(xpt, file="demo.csv")
| improve this answer | |
  • 1
    What's R-cran? Maybe you could add a link to this? – Journeyman Geek Jun 24 '12 at 6:23
  • the R-project open source statistical software. Added a link. – Skylar Saveland Jun 24 '12 at 22:24
  • R 3.2.3 Windows. I did the following: library('foreign') data = read.xport("C:\\Users\\x\\Downloads\\aaa.XPT") write.csv(data, file="C:\\Users\\x\\Downloads\aaa.csv) – thinkanotherone Jan 12 '16 at 22:59

SAS Institute (the company that makes SAS) produces a viewer for SAS data sets.

Note that SAS program files usually have the extension .sas, whereas the data files themselves usually have the extension .sas7bdat.

| improve this answer | |

You can extract data from .SAS7BDAT files using dsread from Oceanview Consultancy, see


It handles files from most platforms though may require registration for some platforms. It's a fast and easy-to-use command-line Windows program that also runs under Wine on Linux. No installation required, just run the .exe.

I realise that this is an old question but it shows up in relevant web searches so including this answer will help anyone else looking to extract data from the proprietary SAS7BDAT format.

Disclaimer: I am the developer of dsread.

| improve this answer | |

If you're talking about SAS XPT files, you can use the xport Python module.

import xport

with open('example.xpt', 'rb') as f:
    for row in xport.Reader(f):
        print row
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.