Had you thought of using PROC MEANS to calculate the median and inter-quartile range without a macro loop? You use the VAR sub-statement to identify the variables you have in &outliers. You could use the output data set in a DATA step to generate the code with CALL EXECUTE for another DATA step to do the final calculation. This requires only two passes through the original data set, no macro code and no splitting and joining. While developing the generated DATA step, replace the CALL EXECUTE with output to a file so you can see what is happening and run the generated code manually.