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

New to IML (just got it, for accessing R).  I'd like to run multiple datasets through R, and create multiple datasets from R run.

Using some of the really good posts by Rick Wicklin, I think I'm pretty close, but can't figure out the last step (creating separate datasets for each loop through the do loop).  Below is the code I'm using (i dummied a couple datasets for demo purposes)

-- any suggestions would be greatly appreaciated.

Thanks,

Dave

 

 

/*Demo Datasetss*/
data in1; retain id g_yr1 g_yr2 ss_yr1 ss_yr2;
do id = 1 to 100;
g_yr1 = 3; g_yr2 = 4; ss_yr1 = rannor(0); ss_yr2 = rannor(0) + .5; output;
end;
run;
data in2; retain id g_yr1 g_yr2 ss_yr1 ss_yr2;
do id = 1 to 100;
g_yr1 = 3; g_yr2 = 4; ss_yr1 = rannor(0); ss_yr2 = rannor(0) + .5; output;
end;
run;

 

proc IML;
dsnames = "in1":"in2";
outnames = "out1":"out2" ;
outnames = {out1 out2};
do i = 1 to ncol(dsNames);
use (dsNames[i]);
read all into X;
create dt from x;
append from x;
close dt;


run ExportDataSetToR("dt", "dataframe" );

 

submit /R;
library("SGPdata")
library("SGP")
library("foreign")
sgpData34<- dataframe
g5_sgp34 <- studentGrowthPercentiles(panel.data = sgpData34, sgp.labels=list(my.year =2014, my.subject="MATH"),
num.prior = 1, grade.progression =3:4)
exp <- g5_sgp34$SGPercentiles$MATH.2014
endsubmit;

 

call ImportDataSetFromR("R_exp", "exp");

 

use R_exp;
read all into x1;
create outx from x1;
append from x1;
close outx;
close R_exp;


/* here is where I'd like to "create" dataset out1 and out2 (based on the value of i), from the dataset R_exp*??*//

 

close (dsNames[i]);
end;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Since your ultimate goal seems to be to transfer data between SAS data sets and R data frames, I suggest you transfer the data directly by using the ExportDataSetToR  and  ImportDataSetFromR subroutines.  It looks like you aren't actually using the SAS/IML matrices for anything, so why create them?

 

I believe you can just say

call ExportDataSetToR(dsnames[i], "dataframe");

 

then after R has run call

 

call ImportDataSetFromR(outnames[i], "exp");

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

Since your ultimate goal seems to be to transfer data between SAS data sets and R data frames, I suggest you transfer the data directly by using the ExportDataSetToR  and  ImportDataSetFromR subroutines.  It looks like you aren't actually using the SAS/IML matrices for anything, so why create them?

 

I believe you can just say

call ExportDataSetToR(dsnames[i], "dataframe");

 

then after R has run call

 

call ImportDataSetFromR(outnames[i], "exp");

 

Dave25
Quartz | Level 8
looks like I made this WAY more complicated than needed - your solution works prefect - thanks!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1044 views
  • 1 like
  • 2 in conversation