Reputation: 61
I need some help... I got some troubles reading my sas table in python using the pandas function read_sas. I got the following error:
"ValueError: Length of values does not match length of index".
Here is the code I run:
import pandas as pd
data=pd.read_sas("my_table.sas7bdat")
data.head()
My sas table is pretty big with 505 columns and 100 000 rows.
Thanks all for your help.
Upvotes: 6
Views: 5348
Reputation: 2144
I had the same problem with few sas files. I solved it in 2 ways: 1. encoding
df=pd.read_csv('foo.sas7bdat.csv', encoding='iso-8859-1')
2. With sas7bdat library installed in Anaconda with:
conda install -c prometeia/label/pytho sas7bdat
In python file:
from sas7bdat import SAS7BDAT
f=SAS7BDAT('foo.sas7bdat').to_data_frame()
Upvotes: 4
Reputation: 61
A solution I found is to export my sas table as a csv file with the code down below:
proc export data=my_table
outfile='c:\myfiles\my_table.csv'
dbms=csv
replace;
run;
After that, I use pandas function read_csv to read the csv file I have just created:
import pandas as pd
data=pd.read_csv("my_table.csv")
data.head()
Hope this might help.
Upvotes: 0