DATA Step, Macro, Functions and more

is function call to another function call allowed in fcmp?

Reply
Frequent Contributor
Posts: 133

is function call to another function call allowed in fcmp?

I am translating my friend's vba code to sas.

I defined function f_lin

then I defined f_2_shift(t) to call this f_lin,

then I use f_2_shift(t) in data set final.

Is this allowed? my sas is only sas is only 9.1, which can't run fcmp proc, so wondering if anybody knows?

proc fcmp outlib=sasuser.ftn.shock;
Function f_lin(a , b,  fa , fb , t );
    rtn = fa + (t - a) * (fb - fa) / (b - a);
    return(rtn);
Endsub;
run;

Function f_2_shift(t);
    If t <= 0.5 or t >= 5 Then   rtn = 0;
    Else If t <= 2  Then  rtn = f_lin(0.5, 2, 0, 1, t);
              Else  rtn = f_lin(2, 5, 1, 0, t);
    return(rtn);
Endsub;


data unshifted;
input
Years
Unishifted;
cards;
0.5 0.06
1 0.0995
1.5 0.114
2 0.1285
2.5 0.17625
3 0.224
3.5 0.32975
4 0.4355
4.5 0.562
5 0.6885
5.5 0.806875
6 0.92525
6.5 1.043625
7 1.162
7.5 1.242833333
8 1.323666667
8.5 1.4045
9 1.485333333
9.5 1.566166667
10 1.647
10.5 1.7015
11 1.756
11.5 1.8105
12 1.865
12.5 1.900666667
13 1.936333333
13.5 1.972
14 2.007666667
14.5 2.043333333
15 2.079
15.5 2.096
16 2.113
16.5 2.13
17 2.147
17.5 2.164
18 2.181
18.5 2.198
19 2.215
19.5 2.232
20 2.249
20.5 2.2578
21 2.2666
21.5 2.2754
22 2.2842
22.5 2.293
23 2.3018
23.5 2.3106
24 2.3194
24.5 2.3282
25 2.337
25.5 2.3427
26 2.3484
26.5 2.3541
27 2.3598
27.5 2.3655
28 2.3712
28.5 2.3769
29 2.3826
29.5 2.3883
30 2.394
;

data final;
set unshifted;
do t=1 to 30 by 0.5;
llatest = 0.01 * Unishifted+ 0.01 shift_size*f_2_shift(t);
output;
end;
run;

Ask a Question
Discussion stats
  • 0 replies
  • 102 views
  • 0 likes
  • 1 in conversation