BookmarkSubscribeRSS Feed
sasuser92
Fluorite | Level 6

I am trying to save a SAS dataset having Unicode characters using R and IML in the RData format using R's save command, and am getting the following errors:

 

ERROR: SAS is unable to transcode character data to the R encoding.

 

The program runs OK if the dataset does not have any Unicode character. I am using SAS with Unicode support to run the program. Any tips to resolve this will be really appreciated.

15 REPLIES 15
ballardw
Super User

It may help a lot to show the code that generates the error and indicate which variables hold values that may include Unicode characters. Better is to include the code along with the notes and messages from the log. Copy the log with the code and all messages and paste into a text box opened on the forum with the </> icon above the message window.

 

Best would be to provide example data along with the code so someone with experience can actually test possible solutions. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

sasuser92
Fluorite | Level 6

Added a minimal example to reproduce the error.

sasuser92
Fluorite | Level 6
Added a minimal example to reproduce the error.
SASKiwi
PROC Star

I suspect you are going to have to align your SAS session encoding with R's encoding or vice versa. You can confirm what your SAS session encoding is by running this:

proc options option = encoding;
run;

Please post your SAS log from the above.

sasuser92
Fluorite | Level 6

Here are two minimal examples, the first one works and the second one does not:

 

 

*** WORKS;
data tab1;
    input symbol $;
    datalines;
	+
;
run;

proc iml;
    run ExportDataSetToR("tab1", "tab1");
    submit / R;
	  print(tab1)
	endsubmit;
quit;

*** DOES NOT WORK;
data tab2;
    input symbol $;
    datalines;
	≤
;
run;

proc iml;
    run ExportDataSetToR("tab2", "tab2");    
    submit / R;
	  print(tab2)
	endsubmit;
quit;

I get the following error on running the second piece of code:

NOTE: IML Ready
126      run ExportDataSetToR("tab2", "tab2");
ERROR: SAS is unable to transcode character data to the R encoding.
ERROR: Unable to export data.
ERROR: Execution error as noted previously. (rc=1000)

 

yabwon
Amethyst | Level 16

Hi @sasuser92 

 

It looks like I get to this topic is a little bit late.

 

I faced similar issue recently. My session setup is:

1    proc options option=RLANG;
2    run;

    SAS (r) Proprietary Software Release 9.4  TS1M9

 RLANG             Enables SAS to execute R language statements.
NOTE: PROCEDURE OPTIONS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


3
4    %put &=sysencoding. &sysvlong4.;
SYSENCODING=utf-8 9.04.01M9P06042025
5    options set=R_HOME="X:/R/R-4.5.2/";
6    PROC IML;
NOTE: Writing HTML Body file: sashtml.htm
NOTE: IML Ready
7      submit / R;
8      sessionInfo()
9      endsubmit;
10   QUIT;
NOTE: Exiting IML.
NOTE: PROCEDURE IML used (Total process time):
      real time           0.25 seconds
      cpu time            0.03 seconds

and the sessionInfo() returns:

yabwon_0-1764234317553.png

 

With the "default" settings as above when I run:

data test;
input symbol $ 9.;
datalines;
空手道
;
run;

proc iml;
    run ExportDataSetToR("test", "test");    
    submit / R;
	  print(test)
	endsubmit;
quit;

I get:

yabwon_2-1764234536120.png

 

But when I've edited the Rprofile file (in my case located in X:\R\R-4.5.2\etc\Rprofile.site) and added:

Sys.setlocale("LC_ALL","en_US.utf8")

The transcoding error dissipated and text was printed:

yabwon_3-1764234703271.png

Unfortunately SAS also started printing this strange warning in the log:

yabwon_4-1764234751887.png

also the "locale" part from the sessionInfo() has this strange text:

yabwon_5-1764234807290.png

 

 

It looks like SAS (when calling R under Windows) assumes 1252 encoding, and even when Rprofile sets it differently, SAS does not respect that??

 

Hope it helps a little bit.

 

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



sasuser92
Fluorite | Level 6

This is the encoding for my SAS session:

 

132  proc options option = encoding;
133  run;
SAS (r) Proprietary Software Release 9.4  TS1M6
ENCODING=UTF-8    Specifies the default character-set encoding for the SAS session.
sasuser92
Fluorite | Level 6

Any help with this issue ? Thanks!

Patrick
Opal | Level 21

As @SASKiwi already mentioned the likely issue here is that your R session doesn't match the SAS session. 

With the SAS session being UTF-8 a likely resolution (to be tested) could be:

export LANG=en_US.UTF-8 set in the appropriate config file .cfg
sasenv_local is also possible.

This is something a SAS admin at your site would need to configure.

I do know that above was the resolution for someone who encountered the same error message than you.

SASKiwi
PROC Star

I suggest you Google R language encoding and check out the links provided. I did and found a number of helpful links. However I'm not an R user so there is no point in me trying to pass on secondhand information, when you can more easily figure out what might be useful or not.

 

Alternatively open a track with SAS Tech Support.

sasuser92
Fluorite | Level 6

I am trying to save a SAS dataset having Unicode characters using R and IML in the RData format using R's save command, and am getting the following errors:

 

ERROR: SAS is unable to transcode character data to the R encoding.

 

The program runs OK if the dataset does not have any Unicode character. I am using SAS with Unicode support to run the program. Any tips to resolve this will be really appreciated.

 

Here is sample code to reproduce the error:

*** WORKS;
data tab1;
    input symbol $;
    datalines;
	+
;
run;

proc iml;
    run ExportDataSetToR("tab1", "tab1");
    submit / R;
	  print(tab1)
	endsubmit;
quit;

*** DOES NOT WORK;
data tab2;
    input symbol $;
    datalines;
	≤
;
run;

proc iml;
    run ExportDataSetToR("tab2", "tab2");    
    submit / R;
	  print(tab2)
	endsubmit;
quit;

This is the encoding for my SAS session:

132  proc options option = encoding;
133  run;
SAS (r) Proprietary Software Release 9.4  TS1M6
ENCODING=UTF-8    Specifies the default character-set encoding for the SAS session.

Any help will be really appreciated.

Tom
Super User Tom
Super User

What is the encoding from the R session that PROC IML created?

Run this function.

 

Sys.getlocale()
sasuser92
Fluorite | Level 6

I am on Windows and get this:

LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

 

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
  • 15 replies
  • 4859 views
  • 3 likes
  • 6 in conversation