Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import SAS data file into python data frame

Tags:

python

pandas

sas

I'm working on a data set (PSID) that gives data in a SAS format (a .txt and another file containing instructions to interpret the data). I cannot find anything in Python to read this type of data.

Does anyone know of a pre-existing module/script to read SAS data?

Edit (added from a comment to an answer): The data is in ascii/text and the start of a row of data looks like this:

3 10 1015000 150013200 00 002500 00 00

like image 526
pdevar Avatar asked Jun 18 '15 09:06

pdevar


People also ask

Can we connect SAS to Python?

Python is a powerful tool for working with data, and makes the perfect partner to SAS to process data, particularly data that is obtained from online sources where programmers have developed open source Python code to connect to published APIs.

Can Python output a SAS dataset?

In addition, Python provides useful modules to enable users to access and handle SAS datasets and utilize SAS modules from Python via SASPy modules (Nakajima 2018). These functionalities are very useful for users to learn and utilize both the functionalities of SAS and Python to analyze the data more efficiently.


1 Answers

As of version 17, Pandas now supports reading sas files with the .xpt file extension. See this link to pandas documentation for additional details.

df = pd.read_sas('sas_xport.xpt')
like image 111
josiah Avatar answered Sep 19 '22 02:09

josiah