07-11-2017 09:20 AM
Post your code.
%macro mymac(varname); %put Variable as received by macro: &&&varname; %mend; data _null_; call symputx('myvar','mytext','g'); call execute('%mymac(myvar)'); run;
Log from that:
24 %macro mymac(varname); 25 %put Variable as received by macro: &&&varname; 26 %mend; 27 28 data _null_; 29 call symputx('myvar','mytext','g'); 30 call execute('%mymac(myvar)'); 31 run; Variable as received by macro: mytext NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
07-11-2017 10:43 AM
Look at this example: val_m2 values are not updated form call execute.
data have; do i=1 to 10; have= i+1; output; end; run; %macro mymacro(nc); %Global used mg1 mg2; %let mg1= 20; %let mg2= 40; data need; set have nobs= nobs; J= _n_; var0= J * &mg1 / &mg2; var1= var0 + 0.5 * &mg1 / &mg2; var2= var0 + var1; nexp= var2 * &mg1 / &mg2; need + (((nexp - have)**2) / nexp); /*cumulative sum*/ if J= nobs then call symput('used',need); run; %mend; data see; do i= 1 to 3; if i= 1 then do; max= 40; min= 15; m1= 27.5; val_m1= 2; m2= 33.75; call execute('%mymacro('||m2||')'); val_m2= input(symget('used'), 30.); /*updating*/ end; else do; min= m1; m1= m2; val_m1= val_m2; m2= (m2 + max)/2; /*updating*/ call execute('%mymacro('||m2||')'); val_m2 = input(symget('used'), 30.); end; output; end; run;
07-11-2017 11:10 AM
The data step in the macro can only be compiled and run after the data step with the call execute has finished. Macro code in a macro that is call executed, OTOH, will be resolved immediately when pushed into the SAS interpreter queue.
If you want to use data from a second dataset dynamically, but in a way that can not be handled by a join, consider using a hash object.
Since you only use an overall statistic from dataset have, I'd prepare that beforehand. No need to reread the whole dataset in every iteration.
07-11-2017 11:24 AM
Since dataset 'have' never changes, and only the results of the final iteration of the data step are put into the macro variable, and the code in the macro is not dynamic at all, there is no need to call the macro at all. Just set &need once.
If you plan on doing something completely different, show THAT code.
07-11-2017 11:50 AM
Where you use these two lines in the data step:
call execute('%mymacro('||m2||')'); <= creates a call to the macro that executes AFTER the data step
val_m2= input(symget('used'), 30.); <= so the value of USED is not changed prior to this line. It will be the same value for every iteration
Do you intentionally through away and decimal part of used?