I am trying to run R script within SAS.
Windows 10, x64 environment
I have followed examples previously published including:
https://pharmasug.org/proceedings/2019/ST/PharmaSUG-2019-ST-149.pdf
https://communities.sas.com/t5/SAS-Programming/How-to-Run-R-code-inside-SAS-easily/td-p/210116
It appears to be set up correctly
1 proc options option=rlang;
2 run;
SAS (r) Proprietary Software Release 9.4 TS1M8
RLANG Enables SAS to execute R language statements.
NOTE: PROCEDURE OPTIONS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
However, when I attempt to run R script, I get an error message regarding the R package 'stats'.
4 proc iml;
NOTE: Writing HTML Body file: sashtml.htm
NOTE: IML Ready
5 submit / R;
6 endsubmit;
WARNING: R: During startup - Warning message:
WARNING: R: package 'stats' in options("defaultPackages") was not found
ERROR: R: Error in is.ts(a) : could not find function "is.ts"
ERROR: SAS is unable to transcode character data to the R encoding.
statement : SUBMIT at line 5 column 5
7 quit;
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 2.56 seconds
cpu time 0.75 seconds
The 'stats' package appears to be installed and runs fine within RStudio. The is.ts function seems to be associated with time series analysis, although that really has nothing to do with the SAS PROC IML script above.
Any thoughts or suggestions on resolving this error would be appreciated. Thank you.
What is your SAS session encoding?
Looks like it may be different than R's.
Bart
I'm not familiar with SAS "encoding".
10 proc options option=encoding;
11 run;
SAS (r) Proprietary Software Release 9.4 TS1M8
ENCODING=WLATIN1 Specifies the default character-set encoding for the SAS session.
NOTE: PROCEDURE OPTIONS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
try to run SAS in UTF-8, it's called "SAS (Unicode Support)"
also R_HOME may help:
proc options option=RLANG;
run;
options set=R_HOME="/path/to/R/R-4.3.1/";
PROC IML;
submit / R;
endsubmit;
QUIT;
this hot-fix helped me too:
https://support.sas.com/kb/70/253.html
Bart
Thank you for the suggestions. Unfortunately, I still get the same error messages.
9 proc options option=encoding; run;
SAS (r) Proprietary Software Release 9.4 TS1M8
ENCODING=UTF-8 Specifies the default character-set encoding for the SAS session.
NOTE: PROCEDURE OPTIONS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
10 proc options option=rlang; run;
SAS (r) Proprietary Software Release 9.4 TS1M8
RLANG Enables SAS to execute R language statements.
NOTE: PROCEDURE OPTIONS used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
11
12 proc iml;
NOTE: IML Ready
13 submit / R;
14 endsubmit;
WARNING: R: During startup - Warning message:
WARNING: R: package 'stats' in options("defaultPackages") was not found
ERROR: R: Error in is.ts(a) : could not find function "is.ts"
ERROR: SAS is unable to transcode character data to the R encoding.
statement : SUBMIT at line 13 column 5
15 quit;
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.54 seconds
cpu time 0.03 seconds
The R_HOME path is already set in the config file. I did try running the options statement that you suggested anyway, but that did not resolve the issue either.
I will continue browsing the hot-fixes.
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.