Hi, I want to ask if this is possible.
data DataSet;
call streaminit(1);
do Set=1 to 3;
do Number=1 to 10;
Variable=rand("normal");
output;
end;
end;
run;
proc iml;
do IMLSet=1 to 3;
use DataSet(where=(Set=IMLSet));
read all var{Variable};
close DataSet;
end;
quit;
In this case, DataSet contains Variable, which is indexed by both Set and Number. In IML, I intended to load DataSet Set by Set so used a loop with an IML variable IMLSet, but this does not work since the "where" only uses the variables in DataSet and it does not have IMLSet there. Alternatives are welcome.
KSharp's solution is good. To read more about how to use the WHERE clause with dynamic values that change in a loop. See
The only improvement I'd suggest to KSharp's code is to put the USE and CLOSE statements outside the DO loop. There is no need to open/close the data set multiple times. You can apply his solution to the OP's original attempt, as follows:
proc iml;
use DataSet;
do IMLSet=1 to 3;
read all var{Variable} where(Set=(IMLSet));
print Variable;
end;
close DataSet;
quit;
data DataSet;
call streaminit(1);
do Set=1 to 3;
do Number=1 to 10;
Variable=rand("normal");
output;
end;
end;
run;
proc iml;
use dataset;
read all var{set};
close;
level=unique(set);
do i=1 to ncol(level);
use dataset;
read all var _all_ into x where (set=(level[i]));
print x;
close;
end;
quit;
P.S. If you really want learn IML code, I really suggest you to read Rick's blog .You can find most answer of IML in it .
KSharp's solution is good. To read more about how to use the WHERE clause with dynamic values that change in a loop. See
The only improvement I'd suggest to KSharp's code is to put the USE and CLOSE statements outside the DO loop. There is no need to open/close the data set multiple times. You can apply his solution to the OP's original attempt, as follows:
proc iml;
use DataSet;
do IMLSet=1 to 3;
read all var{Variable} where(Set=(IMLSet));
print Variable;
end;
close DataSet;
quit;
Yeah. I know what Rick mean. So here is the code revisited.
data DataSet;
call streaminit(1);
do Set=1 to 3;
do Number=1 to 10;
Variable=rand("normal");
output;
end;
end;
run;
proc iml;
use dataset;
read all var{set};
level=unique(set);
do i=1 to ncol(level);
read all var _all_ into x where (set=(level[i]));
print x;
end;
close;
quit;
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.