XPT to CSV Conversion?

I believe there is a read.xport function in one or more packages in R that will read SAS transport files. From there you can use something like write.csv to save it out.


Googling convert "convert sas to csv" turned up this link, which points to a couple of possible solutions.

AM Statistical Software is free statistical software produced by the American Institutes for Research that looks like it can import SAS transport files, and output files in ~150 different formats. I'd guess that .csv is among them!


If you can use Python, I've just published a library that might be able to help with this. Dumping to a CSV would look something like this (untested):

import xport, csv
with xport.XportReader('in.xpt') as reader:
    with open('out.csv', 'rb') as out:
        writer = csv.DictWriter(out, [f['name'] for f in reader.fields])
        for row in reader:
            writer.writerow(row)

The files are treated as streams, so it shouldn't matter how large the file is (as long as you don't call reader.record_count(), which has to seek to the end of the file).

Let me know if you try this -- the library works for me, but I haven't tried it on many .xpt files yet.

Tags:

Csv

R

Sas