| Date: | Thu, 23 Nov 2006 23:01:02 -0800 |
| Reply-To: | RolandRB <rolandberry@HOTMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | RolandRB <rolandberry@HOTMAIL.COM> |
| Organization: | http://groups.google.com |
| Subject: | Re: A question about how to let user defined macro returns |
|
| In-Reply-To: | <1164334257.352488.327340@l12g2000cwl.googlegroups.com> |
| Content-Type: | text/plain; charset="us-ascii" |
|---|
Stig Eide wrote:
> Gerhard Hellriegel wrote:
> > example:
> >
> > %macro double(x);
> > %let res=%eval(&x*2);
> > &res;
> > %mend;
> >
> > %let test=%double(8);
> >
> >
> > But be careful with the usage:
> >
> > data a;
> > set sashelp.class;
> > *double_age=%double(age); /* this will not work */
> > quad_age=age*%double(2);
> > put quad_age;
> > run;
> >
> > Regards,
> > Gerhard
> >
> You must be aware that the macro will resolve before the program is
> run, so the value of age is not known at the time the macro is
> resolved.
> If you want to resolve a macro during execution, you need to use the
> resolve function:
> double_age=resolve('%double('!!put(age,2.)!!')''');
> Documentation:
> http://support.sas.com/onlinedoc/913/getDoc/no/mcrolref.hlp/a000210258.htm
> Stig
You can have a macro that just resolves into sas code and then it will
work fine inside a data step. Here is my %age macro to illustrate.
http://www.datasavantconsulting.com/roland/spectre/macros/age.sas
|