The following example is very simple and might be solvable in an easier way. However, I am interested in making it work. The following example is based on the cars-dataset of the sashelp-library. First, I have a macro called fun:
proc contents data = sashelp.cars out = mycontents;
run;
%macro fun(var);
proc sql noprint;
select count(distinct(&var.))
into :obs
from sashelp.cars;
quit;
%mend;
Now I want to call the macro but only to update obs (from the input statement). I use:
data work.test;
set mycontents;
if name ne "Type" then do;
call execute('%nrstr(%fun('||name||');');
new = &obs;
end;
else new = 5;
run;
In short, this should iterate the rows of the mycontents. Then call one (of several) macros depending on name, which updates obs. Then I can simply populate the new column new with obs. However, obs stays the same value for all names, which is the value from the last variable.
CALL EXECUTE
was important to the question; the title above is a bit broader and will pick up more hits, andCALL EXECUTE
will trigger this post anyway as it's in the body. And i'll add the space, you're correct there. – Joedosubl
look up "Run_MACRO Run!" which is a very good paper on the more advanced use of it. – Joedefine
declare
etc. isn't great either, and any other solution is more wordy, no? (I don't remember what word you used, so maybe I'm missing something...)Immediately
is accurate, I think; immediately as opposed to in the next data step. (could sayin the same data step
but that's wordy, not searchable, and won't tend to be read anyway as it's so far into the title) – Joe