BookmarkSubscribeRSS Feed
cminard
Quartz | Level 8

I am trying to run R script within SAS. 

Windows 10, x64 environment

  • R version 4.5.1
  • SAS version 9.4M8

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.

 

5 REPLIES 5
yabwon
Amethyst | Level 16

What is your SAS session encoding?

Looks like it may be different than R's.

 

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



cminard
Quartz | Level 8

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
yabwon
Amethyst | Level 16

try to run SAS in UTF-8, it's called "SAS (Unicode Support)"

_______________
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



yabwon
Amethyst | Level 16

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

_______________
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



cminard
Quartz | Level 8

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. 

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
  • 5 replies
  • 147 views
  • 0 likes
  • 2 in conversation