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

Hello,

 

I need to import into SAS a CSV file which contains SMS messages.  The SMS message can include emojis.  Whenever I use either PROC IMPORT or an INFILE statement to read in an emoji, the program fails with the message:

 

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

 

The rest of the file is not imported into SAS.

 

An example of a CSV file with an emoji is: (taken from the attached file)

"Delivery Status","Question Label","Question DateTime","Answer Label","Answer DateTime","Answer Text"

"Delivered","3","02/07/2019 08:22:39","Invalid Response","04/07/2019 10:31:43","😊"

 

I would like to either get SAS to ignore the emoji and carry on processing the CSV file, or better still, process the emoji and give a text version of this.  I have found examples where people have done this with emoticons, and so I wondered if anyone had updated this to handle emojis.

 

I am using EG 7.15 with SAS 9.4.

 

I hope that this is clear.

 

Thanks for any help

Andrew

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Hi @AndrewJones ,

 

tray the code below, it looks like you have UTF file with bit order mask (BOM). I've tested it on my Wlatin1 sas session.

 

Someone smarter than we ( @FreelanceReinh  ) already answered this in the following thread:

https://communities.sas.com/t5/SAS-Programming/Import-issue-Invalid-string-Unrecoverable-I-O-error/t...

 

%put &=sysencoding.;

filename f "C:\Users\&sysuserid.\Downloads\Sample.csv";

data _null_;
  infile f recfm=N;
  input c $char10.;
  put c $hex20.;
  stop;
run;

filename T "%sysfunc(pathname(work))/temp" recfm=N;
data _null_;
  infile f recfm=N;
  file t recfm=N;
  if _n_=1 then input +3 @@; /* skip first three bytes (adapt if BOM is longer) */
  input c $char1.;
  put c $1.;
run;
filename T "%sysfunc(pathname(work))/temp" recfm=V;

data test;
  infile t firstobs=2 DSD ; /*dlm='0a0d'x;*/
  input (DeliveryStatus QuestionLabel QuestionDateTime AnswerLabel AnswerDateTime AnswerText) (: $ 20.);
run;

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

4 REPLIES 4
yabwon
Onyx | Level 15

Hi @AndrewJones ,

 

I did this on your example:

filename f "C:\Users\&sysuserid.\Downloads\Sample.csv" encoding='utf-8';

data test;
  infile f firstobs=2 DSD;
  input (DeliveryStatus QuestionLabel QuestionDateTime AnswerLabel AnswerDateTime AnswerText) (: $ 20.);
run;

and it worked. Are you working in UTF-8 session? 

 

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



AndrewJones
Obsidian | Level 7

Hi Bart,

 

Thanks for your quick reply.  I tried your code below and I still got the error message.  I am working in a WLATIN1 environment.  SAS is installed on a server and so I don't want to change the default encoding since this will affect all other users.  Is there are way to handle this programmatically?

 

Thanks

Andrew

yabwon
Onyx | Level 15

Hi @AndrewJones ,

 

tray the code below, it looks like you have UTF file with bit order mask (BOM). I've tested it on my Wlatin1 sas session.

 

Someone smarter than we ( @FreelanceReinh  ) already answered this in the following thread:

https://communities.sas.com/t5/SAS-Programming/Import-issue-Invalid-string-Unrecoverable-I-O-error/t...

 

%put &=sysencoding.;

filename f "C:\Users\&sysuserid.\Downloads\Sample.csv";

data _null_;
  infile f recfm=N;
  input c $char10.;
  put c $hex20.;
  stop;
run;

filename T "%sysfunc(pathname(work))/temp" recfm=N;
data _null_;
  infile f recfm=N;
  file t recfm=N;
  if _n_=1 then input +3 @@; /* skip first three bytes (adapt if BOM is longer) */
  input c $char1.;
  put c $1.;
run;
filename T "%sysfunc(pathname(work))/temp" recfm=V;

data test;
  infile t firstobs=2 DSD ; /*dlm='0a0d'x;*/
  input (DeliveryStatus QuestionLabel QuestionDateTime AnswerLabel AnswerDateTime AnswerText) (: $ 20.);
run;

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



AndrewJones
Obsidian | Level 7

Hi @yabwon,

 

Perfect.  This works like a charm.  Thanks for finding the solution.

 

Cheers

Andrew

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 3246 views
  • 3 likes
  • 2 in conversation