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.
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.
Added a minimal example to reproduce the error.
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.
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)
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:
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:
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:
Unfortunately SAS also started printing this strange warning in the log:
also the "locale" part from the sessionInfo() has this strange text:
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
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 with this issue ? Thanks!
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.
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.
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.
What is the encoding from the R session that PROC IML created?
Run this function.
Sys.getlocale()
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.