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

Hallo,

I am trying to import a csv file. In this file the first line, the one containing the variables name, contains some names with utf-8 characters.

I'm working with SAS 9.4.

 

First try to import the code without considering the special characters using the "wlatin1" encoding.

filename P1 "C:\Temp\Test_UTF_8.csv" encoding='wlatin1';

proc import datafile=P1 dbms=csv replace out=raw;
delimiter=';';
run;

In this case the code is working but the columns containing the special characters like "ä".

 

When I try to change the encoding using "utf-8" 

filename P1 "C:\Temp\Test_UTF_8.csv" encoding='utf-8';

proc import datafile=P1 dbms=csv replace out=raw;
delimiter=';';
run;

the code is not working and I get the error:


ERROR: Invalid string.
FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.
Aborted during the INITIALIZE EXECUTION phase.

 

 Has someone a solution to this problem or can give me an hint where to look.

Thanks a lot

 

Paolo

 

In attachment you find the file I'm trying to import and the log file.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You need a special option " options validvarname=any ".

 

options validvarname=any;
filename P1 "C:\Temp\Test_UTF_8.csv" encoding='wlatin1';
proc import datafile=P1 dbms=csv replace out=raw;
delimiter=';';
run;

View solution in original post

3 REPLIES 3
Ksharp
Super User

You need a special option " options validvarname=any ".

 

options validvarname=any;
filename P1 "C:\Temp\Test_UTF_8.csv" encoding='wlatin1';
proc import datafile=P1 dbms=csv replace out=raw;
delimiter=';';
run;
Tom
Super User Tom
Super User

Your file does not contain UTF-8 characters  In fact the extended ASCII characters it does have are using some of the values that UTF-8 uses to indicate multi-byte character encoding and that is what is causing the errors when you treat it as a UTF-8 encoded text.

 

Note since you are reading a text file you can just write your own data step to read the data.  Then you can control the variable names that will be used.

Paolo_Corti
Calcite | Level 5

Thank a lot for the answers! 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 16288 views
  • 0 likes
  • 3 in conversation