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;
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");
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");
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.