|
Summary: Macros execute at SAS compiletime
#iw-value=1
Tree,
Richard said it, then Data_null_ said it differently, and my summary
line said it again, but a log with some %PUT statements may be more
revealing.
1 %macro maxprecision(ul,ll);
2 %let ind_ul=%sysfunc(index(&ul,.));
3 %let rem_ul=%sysfunc(substr(&ul,%eval(&ind_ul+1)));
4 %let lgt_ul=%sysfunc(length(&rem_ul));
5 %let ind_ll=%sysfunc(index(&ll,.));
6 %put ind_ll=>>>&ind_ll<<<;
7 %let rem_ll=%sysfunc(substr(&ll,%eval(&ind_ll+1)));
8 %put rem_ll=>>>&rem_ll<<<;
9 %let lgt_ll=%sysfunc(length(&rem_ll));
10 %put lgt_ll=>>>&lgt_ll<<<;
11 %if %eval(&lgt_ul>&lgt_ll) %then %do;
12 %let lgtf=z&lgt_ul..;
13 %end;
14 %else %do;
15 %let lgtf=z&lgt_ll..;
16 %end;
17 %put lgtf=>>>&lgtf<<<;
18 %let q = 0.%sysfunc(sum(1),&lgtf) ;
19 %put q=>>>&q<<<;
20 &q
21 %mend;
22
23 data _null_ ;
24 ll = 3 ;
25 tree_frog = %maxprecision(ll,ohmywhichvar) ;
ind_ll=>>>0<<<
rem_ll=>>>ohmywhichvar<<<
lgt_ll=>>>12<<<
lgtf=>>>z12.<<<
q=>>>0.000000000001<<<
26 data_null_ = %maxprecision(3,5.55) ;
ind_ll=>>>2<<<
rem_ll=>>>55<<<
lgt_ll=>>>2<<<
lgtf=>>>z2.<<<
q=>>>0.01<<<
27 put _all_ ;
28 run ;
ll=3 tree_frog=1E-12 data_null_=0.01 _ERROR_=0 _N_=1
Take a look at www2.sas.com/proceedings/sugi31/042-31.pdf
to test your understanding.
Ian Whitlock
===============
Date: Wed, 28 Nov 2007 15:25:15 -0800
Reply-To: Tree Frog <tree.frog2@HOTMAIL.COM>
Sender: "SAS(r) Discussion"
From: Tree Frog <tree.frog2@HOTMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Arithmetic precision comparison
Comments: To: sas-l
Content-Type: text/plain; charset=ISO-8859-1
Folks
Albeit that I was well off track with my expensive and flawed
%sysfunc-
ing bonanaza above, can someone explain how come my proposed solution
doesn't work in a data step - why it doesn't resolve the arguments to
their data step variable values, and instead treats them as macro
variables?
I think there's something missing or forgotten in my understanding of
macro, isn't there!
TIA
Tree Frog
<snip>
|