01-27-2016 06:44 PM
Can I call/execute macro within a DO loop?
data TWO; set ONE;
%macro( some variable in TWO, ONE, maybe another dataset )
is this possible? thx a lot.
01-28-2016 02:20 AM
You do not "execute" the macro in the loop. Instead, during the data step compilation phase, the macro is resolved, and the resulting text is inserted as code in the loop, in place of the macro call. Once compilation has finished successfully (meaning the resulting data step code is syntactically correct), the whole code is executed; at data step runtime, no macro elements are therefore present, having been resolved beforehand.
If you use call execute, be aware that the data step feeds then code into the main SAS interpreter's input queue, and this code is dealt with after the data step has finished. Also be aware that macro references in a call execute will once again be resolved before the data step starts, unless you prevent that by proper quoting or other means (eg reading macro names from a dataset).
01-28-2016 06:25 AM
What are you trying to do, post test data, in the form of a datastep - and the output you are looking for. The question is too general as it is, yes you could have that macro there, if it generates valid code for its place, yes you could call execute - again if the macro is valid. But we don't know anything around the code, so can't advise.
01-28-2016 07:17 AM
Actually, this question originates from this:
Really desparately crasy...
01-28-2016 08:06 AM
Well, I don't really know what the "regression" part is, am not a statistician, so can't help there. Call execute is used to generate code, it won't speed anything up for you. You will still need to select your data, then run your procedure on it. If it is taking a long time, then consider subsetting, or aggregating your data first. I.e.
set total (where=(id=1));
Call execute can be used to generate the code per row of your data, but all that means is there will be a vast amount of code all running quickly, rather than a small bit of code running slowly, which will probably end up being more or less the same. SAS procedures and datasteps are optimised, so the more grouping you can do and in the fewer datasteps the better, using datastep rather than SQL might also reduced the resource usage.