BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sreevatsan1991
Obsidian | Level 7

When I try to read the csv file saved by SAS into python, I am getting unicode-decode error. The error was because of '0x80' character available in the file. it can be solved by explicitly defining the encoding when reading the file. But I need to solve it to in SAS while creating the .csv file.

Is there a way to define the encoding in the proc export code like (encoding='utf-8' etc

 

Code :

PROC EXPORT DATA= data1
OUTFILE= "F:\reports\&file_name..csv"
DBMS=CSV REPLACE;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Did you try using a fileref?

filename csv "F:\reports\&file_name..csv" encoding='utf-8';
PROC EXPORT DATA= data1 REPLACE
  OUTFILE= CSV DBMS=CSV 
;
RUN;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Did you try using a fileref?

filename csv "F:\reports\&file_name..csv" encoding='utf-8';
PROC EXPORT DATA= data1 REPLACE
  OUTFILE= CSV DBMS=CSV 
;
RUN;
Reeza
Super User

Try assigning a FILEREF to the output data set and set the encoding there.

 

filename myfile 'paht to file' encoding=....;

proc export data=data outfile=myfile dbms=csv replace;
run;

@sreevatsan1991 wrote:

When I try to read the csv file saved by SAS into python, I am getting unicode-decode error. The error was because of '0x80' character available in the file. it can be solved by explicitly defining the encoding when reading the file. But I need to solve it to in SAS while creating the .csv file.

Is there a way to define the encoding in the proc export code like (encoding='utf-8' etc

 

Code :

PROC EXPORT DATA= data1
OUTFILE= "F:\reports\&file_name..csv"
DBMS=CSV REPLACE;
RUN;


 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3467 views
  • 2 likes
  • 3 in conversation