Search code examples
syntaxsasmacrossas-macro

Call Incremental Datasets Created by Macro Function


I have a macro variable called max_attempts I created from a a PROC SQL that equals 4 for my current datafile. Then, I used a macro function to create datasets up to max_attempts so now I have attempt1_table, attempt2_table, attempt3_table, and attempt4_table. Now I'm having trouble merging the 4 datasets.

data final_table;
    set attempt1_table - attempt&max_attempts._table;
run;

enter image description here The inputted datafile will have a different max_n each time, so I'm using macros to account for that.


Solution

  • Thank you everyone for your help! It was two issues, the number has to be at the end of the dataset name when using the - shortcut and using trimmed to remove leading spaces.

    proc sql feedback;
        select max(max_attempts)
            into: max_attempts trimmed
            from analysis_data;
    quit;    
    
        
    data analysis_table;
        set unknown_table attempt_table1 - attempt_table&max_attempts;
    run;