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;


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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