BookmarkSubscribeRSS Feed
Xiyuan
Fluorite | Level 6

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

 

6 REPLIES 6
Xiyuan
Fluorite | Level 6
The format of X and Y are both numeric
PeterClemmensen
Tourmaline | Level 20

Use Call Execute logic and the macro in combination. 

 

For a more detailed answer, provide sample data please.

Patrick
Opal | Level 21

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
tarheel13
Rhodochrosite | Level 12

have you considered proc fcmp? I think it can help you here. 

Tom
Super User Tom
Super User

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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 990 views
  • 1 like
  • 6 in conversation