开发者

XPT to CSV Conversion? [closed]

开发者 https://www.devze.com 2023-04-11 20:34 出处:网络
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 3 years ago.

Improve this question

Perhaps this is the wrong 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 a comma separated format. The file is too large to load in R. I do not have SAS on my machine, and do not have any way of getting it.

Any suggestions? Is there a converter somewhere? I cannot find one using google.


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.


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!


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.


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

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


To save readers wasting their time, I'll say that I've just tried AM Statistical Software (version 0.06.04 Beta Aug 14 2011). It accepts an impressive variety of SAS files, but not .xpt .


Unfortunately, I'm too new to comment, and this hasn't been active in a while, but I've found that the AM package works perfectly.

You need to download a separate extension from their site, and after experimenting, I've found that you need to select the file type "SAS Transport (*.v5x)", go to the directory, and MANUALLY type in the file name in the respective box. It'll load correctly.

Kind of a weird way to load the file in, but from what I've needed, it works just as people claim on their website.


I realize this thread is quite old. It was the best one I found just now and had several good suggestions. I wanted to add another free option for anyone else who might search for a simple way to convert from XPT to CSV.

SAS makes the SAS Universal viewer that will open several file types for viewing. It will save the file to the CSV format as well. The only file type I tried was XPT and it was incredibly simple and fast.

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

According to the User's Guide for version 1.3: With SAS Universal Viewer, you can view the following types of files:

• SAS data sets, including those that were created on platforms other than Windows

• SAS v5 transport files

• SAS programs, logs, and listings

• general text files

• HTML and other file types that open in Internet Explorer

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

0

精彩评论

暂无评论...
验证码 换一张
取 消