I am trying to use Proc IML to run R code as most of the project's needed processing takes place in SAS. This piece of code runs successfully in R, but when run in SAS, nothing happens, and no errors are reported. I've successfully submitted other chunks of R code via Proc IML submit / R, so have run out of troubleshooting paths.
Any suggestions?
PROC IML ;
submit / R;
library(lubridate)
library(tidyverse)
x=c(dir("X:/path/meta/ms3.out", full.names = TRUE, ignore.case = TRUE))
tmp1=x[1:length(x)]
convert_csv<-function(tmp1) {
load(tmp1)
fname = unlist(strsplit(tmp1,"ms3.out/"))[2]
fname2 = unlist(strsplit(fname,".RData"))[1]
write.csv(sib.cla.sum, file = paste("X:/path/meta/csv","/",fname2,".csv",sep=""))
}
lapply(tmp1,convert_csv)
endsubmit ;
Try options isOK= .
PROC IML ;
submit / R isOK=OK;
.............
endsubmit ;
print OK;
Thanks for the suggestion, but that didn't work.
isOK=OK resulted in an error
OK=isOK resulted in no change from my previous attempts.
Better post is at IML forum @Rick_SAS is there.
Please attatch your ms3.out file, or at least a portion of it.
The files in the ms3.out folder are RData files that I'm just trying to convert to a CSV file. The communities page isn't letting me attach an RData file to this post. Any suggestions would be appreciated!
I guess my first question is what do you mean when you say "nothing happens." Are you saying that the program runs to completion but no CSV files are created?
I suggest you verify that you have write-permission from within SAS to the directory where you are writing the CSV. I assume this directory is on the same machine that SAS is running on?
1. Simplify the program to create a simple data frame and use write.csv to write it to the directory in question.
Might as well verify that you can read the directory, too:
2. Does the program work when you just load() the data?
Presumably, one of those operations will fail.
Yes, exactly. The program runs to completion, but no csv files are created. When I run the exact code in R, it successfully creates the csv files.
The directory is not on the hard drive of the computer, but it should be accessible. I haven't had any issues loading and creating files or new directories in the past in this directory.
It's interesting, when I split it up into 2 main chunks:
Chunk 1:
PROC IML ;
submit / R ;
load("X:/NAYSHAW/NAYSHAW results/output_11055, 11056, 11062, 11066/meta/sleeplog.RData") #ggir log
write.csv(sleeplog, file = paste("X:/NAYSHAW/NAYSHAW results/output_11055, 11056, 11062, 11066/meta/","/","sleeplog.csv",sep="")) #csv log
endsubmit;
and Chunk 2:
submit / R ;
library(lubridate)
library(tidyverse)
x=c(dir("X:/NAYSHAW/NAYSHAW results/output_11055, 11056, 11062, 11066/meta/ms3.out", full.names = TRUE, ignore.case = TRUE))
tmp1=x[1:length(x)]
convert_csv<-function(tmp1) {
load(tmp1)
fname = unlist(strsplit(tmp1,"ms3.out/"))[2]
fname2 = unlist(strsplit(fname,".RData"))[1]
write.csv(sib.cla.sum, file = paste("X:/NAYSHAW/NAYSHAW results/output_11055, 11056, 11062, 11066/meta/csv","/",fname2,".csv",sep=""))
}
lapply(tmp1,convert_csv)
endsubmit ;
Chunk 1 successfully loads and writes the file. But Chunk 2 runs to completion with no resulting CSV files.
I do not know what is going on but I think you are on the right track by breaking up the problem. Does it work if you call the lapply function with a list that contains the 'sleeplog.RData' file which works in the first chunk? How about a hard-coded list with two elements?
I'm not following your suggestion completely as I've had a hard time picking up R. I suppose I'm confused as to why, if the code works in R, it does not work using PROC IML submit / R. It's likely I'm not understanding why the 2 are different in results. Any more suggestions would be appreciated. Or more detail on what you mean by your post.
Depending on where SAS runs, it might not have access to (or permission for) the same directories on your PC that R is accessing.
As I've said, your best bet is to break up the problem to find out what is failing.
It might be helpful if you explain your goal. What are you trying to accomplish? It looks like you are converting R data frames to CSV files, but why? Is that so that SAS can read the CSV? If so, could you use the ImportDataSetFromR function to read the R data directly? Why go through CSV?
Thank you Rick_SAS.
I wasn't really sure how to break up the pieces of the remaining code as it is a function.
Actually, that is exactly what I'm trying to accomplish. The file we are dealing with is created partway through an R package run. We are taking this intermediate file and doing our own processing thereafter, but doing so in SAS. So, yes we just want the RData file to be used in SAS. I will try this function.
Thanks again!
Hi Rick,
I'm also having trouble using the ImportDataSetFromR function. The following code runs successfully, but again there is no result (no output, no listing, etc).
PROC IML ;
submit / R ;
load("X:/path/11055__049771.RData").
sib.cla.sum <- as.data.frame(sib.cla.sum)
endsubmit ;
call ImportMatrixFromR("Work.Mydata", "sib.cla.sum");
use Work.Mydata ;
show contents;
close Work.Mydata ;
QUIT ;
I followed your link but it only included the generic information. There was no accompanying syntax. Are there some tutorials on how to utilize this function and any specifications required?
Thank you!
If you are trying to create a SAS data set, use
call ImportDATASETFromR("Work.Mydata", "sib.cla.sum");
You are calling
call ImportMATRIXFromR("Work.Mydata", "sib.cla.sum");
Hi Rick,
Thank you for this correction. I made the edits and am still coming up with no results and no errors.
Here is my code:
proc options option=rlang; run ;
PROC IML ;
submit / R ;
load("X:/path/file.RData")
RData <- sib.cla.sum
endsubmit ;
call ImportDataSetFromR("Work.Mydata", "RData");
use Work.Mydata ;
show contents;
close Work.Mydata ;
I've confirmed sib.cla.sum is a data frame within the file using attributes. This is what prints in the log:
RLANG Enables SAS to execute R language statements.
NOTE: PROCEDURE OPTIONS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds24
25 PROC IML ;
NOTE: IML Ready
26 submit / R ;
27 load("X:/NAYSHAW/NAYSHAW results/output_testRtoSAS/meta/ms3.out/11055__049771.RData")
28 RData <- sib.cla.sum
29 endsubmit ;
30 call ImportDataSetFromR("Work.Mydata", "RData");
31 use Work.Mydata ;
32 show contents;
33 close Work.Mydata ;
But there is no information in the output and no data set in the WORK directory. I apologize if I'm missing a simple step. Based on the SAS IML User Guide I am expecting some kind of basic output showing the data and a file saved in the work directory.
Thank you!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.