How can I read a SAS-Dataset with a name given as stem+suffix into IML? The stem is given as a SAS macro variable, the suffices I intend to use are in a string-vector in IML.
In R I would use
suffix<-c('s1','s2')
for (s in suffix){
data<-eval(as.name(paste(stem,s,sep='')))
}
I could do the looping if I had the code for the first dataset. I tried:
proc iml;
suffices = {'s1','s2'};
call symput('suffix',suffices[1]);
use &stem.&suffix.;
The problem being that if in a do-loop (and I need this as I loop over names), call symput does not really work. Here i found symget, but in the context of use &stem.symget('suffix') was not fruitful.
Any other ideas?
Edit: I found the following rather inelegant solution:
proc iml;
%global suff;
suffix={'s1','s2','s3'};
%do ii = 1 %to 3;
call symput('suff',suffix[&ii.]);
<do stuff based on the suffix>
%end;
Still I do not feel this is the way one is supposed to work on it.
If you have SAS/IML 12.1, simply use string concatenation to construct the data set name, and then put parentheses around the name, as described in the blog post "Read data sets that are specified in an array".
Be careful when you try to use macro variables in a loop. See the tips in the article "Macros and loops in the SAS/IML language"
The easiest way I can think of to do this is to use some non-IML syntax. PROC SQL for example can generate macro variable lists.