XPT to CSV Conversion?

This may not be the right place for this, but I'm not quite sure where to put it.

I have a very large compressed SAS file in .XPT format. I want to convert it to comma separated format. The file is too large to load in R. I do not have SAS on my machine and I have no way to get it.

Any suggestions? Is there a converter somewhere? I can not find it using Google.

+6
source share
8 answers

Googling convert "convert sas to csv" raised this link , indicating a couple of possible solutions.

AM Statistical Software is a free statistical software created by American research institutes, it looks like it can import SAS transport files and output files in ~ 150 different formats. I would suggest that .csv among them!

+4
source

If you can use Python, I just published a library that could help with this. Dumping in CSV will 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) 

Files are treated as streams, so it doesn't matter how big the file is (unless you call reader.record_count (), which you should look for at the end of the file).

Let me know if you try this - the library works for me, but I have not tried it in many .xpt files yet.

+8
source

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.

+2
source

To save readers who are wasting time, I will say that I just tried AM Statistical Software (version 0.06.04 Beta Aug 14 2011). It accepts an impressive array of SAS files, but not .xpt.

+2
source

Unfortunately, I'm too new to the comments, and it was not active at the time, but I found that the AM package works fine.

You need to download a separate extension from your site, and after the experiment I found that you need to select the file type "SAS Transport (* .v5x)", go to the directory and enter MANUALLY in the file name in the corresponding field. It will load correctly.

Kind of a weird way to upload a file, but from what I need, it works the same way people claim on their website.

0
source

Python has the xport library https://pypi.python.org/pypi/xport/ install the library

 $ pip install xport $ python -m xport example.xpt > example.csv 
0
source

I understand that this thread is quite old. It was the best I found now and had some good suggestions. I wanted to add another free option for anyone who could find an easy way to convert from XPT to CSV.

SAS makes SAS Universal viewer open several types of files for viewing. It will also save the file in CSV format. The only type of file I tried was XPT, and it was incredibly simple and fast.

Link to the SAS website to download: https://support.sas.com/downloads/browse.htm?cat=74

According to the User Guide for version 1.3: Using SAS Universal Viewer you can view the following file types:

• SAS datasets, including those created on platforms other than Windows

• SAS v5 transport files

• Programs, magazines and SAS lists

• common text files

• HTML and other types of files that open in Internet Explorer

https://support.sas.com/documentation/cdl/en/univiewerug/65066/PDF/default/univiewerug.pdf

0
source

In fact, this topic is quite old. But a Google search is still the first result. I tried the AM package. As mentioned earlier, if you rename XPT files to .v5x, they will be read. But with the real number, I had rounding errors. for example, 14.0 became 14.000001

I installed R and with the help of two articles I can convert XPT files to CSV.

-3
source

Source: https://habr.com/ru/post/898992/


All Articles