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;
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.
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.
If you provide details and an example, someone might be able to help.
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.
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.
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.