Loop over names in SAS-IML?

后端 未结 2 396
慢半拍i
慢半拍i 2021-01-22 11:18

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.

相关标签:
2条回答
  • 2021-01-22 11:31

    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"

    0 讨论(0)
  • 2021-01-22 11:47

    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.

    %let stem=class_;
    data class_s1 class_s2;
    set sashelp.class;
    run;
    
    data suffices;
    input suffix $;
    datalines;
    s1
    s2
    ;;;;
    run;
    
    %macro use_suffix(suffix=);
    use &stem.&suffix.;
    read all into &stem.&suffix.;
    print &stem.&suffix.;
    %mend use_suffix;
    
    proc sql;
    select cats('%use_suffix(suffix=',suffix,')') into :suffixlist separated by ' ' from suffices;
    quit;
    
    proc iml;
    &suffixlist;
    quit;
    
    0 讨论(0)
提交回复
热议问题