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

Hi,

 

I am new to R and have been trying out how to integrate R codes in SAS.

In a single SAS program, I have some SAS codes followed by R codes.

Can I call on the SAS datasets (mydataset1 mydataset2) without doing the ExportDataSetToR step?

 

The reason why I'm asking is there seemed to be some limit on the length of the variables in the dataset when doing the ExportDataSetToR step.

 

 

data mydataset1;
set mylibrary.mydataset1;
run;

data mydataset2;
set mylibrary.mydataset2;
run;
proc iml; run ExportDataSetToR("mydataset1", "rdataset1");
run ExportDataSetToR("mydataset2", "rdataset2"); submit / R; #_______Begin of R code_________________ total <- merge(data mydataset1, data mydataset2, by="ID") #_______End of R code_________________ endsubmit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I think I might know the problem that you are reporting. The ExportDataSetToR function uses the R function 'writeBin'. The R documentation for writeBin contains this sentence: "readBin and writeBin read and write C-style zero-terminated character strings. Input strings are limited to 10000 characters."  So if your SAS variable is a character variable whose length is 10,000 or more, you will not be able to transfer it to R from SAS by using the ExportDataSetToR function.

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

The ExportDataSetToR subroutine creates an R data frame from data in a SAS data set. It also converts some variable representations (dates, times, missing values,...) into the analogous R representations. 

 

To answer your question, you are not required to use the ExportDataSetToR subroutine, but I think it is the most reliable and efficient way to form an R data frame from SAS data. If you prefer to import the data some other way (an R package, converting to CSV,...) then you can do so. However, I can't think of an example in which I would recommend that approach.

JJIN
Calcite | Level 5
Thanks. I am having issues with ExportDataSetToR as the length of one of the string variable is very long (address).
Rick_SAS
SAS Super FREQ

If you provide details and an example, someone might be able to help.

Rick_SAS
SAS Super FREQ

I think I might know the problem that you are reporting. The ExportDataSetToR function uses the R function 'writeBin'. The R documentation for writeBin contains this sentence: "readBin and writeBin read and write C-style zero-terminated character strings. Input strings are limited to 10000 characters."  So if your SAS variable is a character variable whose length is 10,000 or more, you will not be able to transfer it to R from SAS by using the ExportDataSetToR function.

Rick_SAS
SAS Super FREQ

I think I might know the problem that you are reporting. The ExportDataSetToR function uses the R function 'writeBin'. The R documentation for writeBin contains this sentence: "readBin and writeBin read and write C-style zero-terminated character strings. Input strings are limited to 10000 characters."  So if your SAS variable is a character variable whose length is 10,000 or more, you will not be able to transfer it to R from SAS by using the ExportDataSetToR function.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 5 replies
  • 1657 views
  • 0 likes
  • 2 in conversation