hi all
I have a dataset with N observations and 2 variables X & Y.
I want to execute a macro function for each observation, that means i need to execute N times.
Each time the inputs of the macro are the values of X and Y, like %fn(input1=X,input2=Y)
How to program as quickly as possible?
Thanks very much
Use Call Execute logic and the macro in combination.
For a more detailed answer, provide sample data please.
I'm not sure that using a SAS Macro is the technical solution to your problem. What would really help: Provide sample data in the form of a SAS data step creating this sample data, show us the desired result based on the sample data, explain the logic how to get from the sample data to the desired result.
Okay, you told us X and Y are numeric (even though that probably doesn't help at this point in time). Now tell us what %FN does.
have you considered proc fcmp? I think it can help you here.
Assuming you called the macro a "function" out of habit and not because you think will behave the same as a SAS function like LOG() or MEAN() you could just generate one macro call per observation.
So assuming that your dataset is named HAVE you could run something like this:
filename code temp;
data _null_;
set have;
file code;
put '%fn(input1=' X ',input2=' Y ')' ;
run;
%include code / source2;
The data step will write one line of code per observation. The %INCLUDE statement will then run the generated lines of code.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.