selik / xport

Python reader and writer for SAS XPORT data transport files.
MIT License
49 stars 24 forks source link

Encode char error #104

Closed doublebro closed 1 year ago

doublebro commented 1 year ago

Tried to export a NHANES data file to csv and encountered the error.

Data file available at: https://wwwn.cdc.gov/nchs/nhanes/search/datapage.aspx?Component=Dietary&Cycle=2017-2020 (at DSII Data [XPT - 74 MB]

Bash CLI: bash-3.2$ python -m xport SAS_NHANES_Data/DSII.XPT > SAS_NHANES_Data/DSII.csv Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main "main", fname, loader, pkg_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/SAS_NHANES_Data/xport-2.0.2/xport.py", line 815, in print(','.join(map(str, row))) UnicodeEncodeError: 'ascii' codec can't encode character u'\x92' in position 55: ordinal not in range(128)

doublebro commented 1 year ago

Apologies, I noticed my MacOS python pointed to version 2.7.16.

I upgraded to version 3.11 and used the below command which worked fine. python3 -m xport SAS_NHANES_Data/DSPI.XPT > SIG731/SAS_NHANES_Data/DSPI.csv

Closing this as it is a non-issue