can i write my own function in sas?

In SAS,if I having a value to return to orther use, I only know that we can use macro variable. Can I use sas language to write my owner function with return value in SAS? Or write my owner macro function with return value in SAS?

Re: can i write my own function in sas?

Yes, you can write macros which operate as functions. For example, suppose you need to compute the study day of a visit, and you have both the visit date and first day of study med (Day 1) on the record. The following macro can be called as a function:

Re: can i write my own function in sas?

Hi Nancy, thanks for your answer. This method sometime may be usefull, but I have a question, can't use this method.
The problem is that: I have a table TRADING_DATE whith variable t_date means all the trading date, with the given date, I must give the last trading date before the given date.
For example, the table have the record, 20030104,20030105,200306,20030109,20030110,....., with the given date 20030108, the last trading date before is 20030106.
Can this writen as a function in SAS?

Here I use the resolve function to delay the execution of the macro %Mult until the data steps execution time. This allows one to pass variable X's values to the macro with each observation. The Data Step releases control to the macro facility where it does the math and the macro facility passes back the new value and releases control back to the data step.

Re: can i write my own function in sas?

Many of the features in SAS and S that I like or dislike are similar to
the last paragraph, in that they are consequences of the way in which the
underlying package is organized. They are not right or wrong, nor can they
be `fixed', but in many particular instances one or the other can be
very inconvenient. Though GUI interfaces are a good thing in their own
right, and are a big help to a certain class of user, they cannot undo some
of these features: PROC INSIGHT is not, nor is it even close to, a
replacement for S graphics.

Re: can i write my own function in sas?

For consideration, I was able to execute the SAS RESOLVE function in SAS 9.1.3 SP4, using the sample code provided by TobyDunn. I remember using this function in the past but never for numeric data calculations though. Thanks to Toby for the extra idea.