|
To make your macro work easier have it generate just that statements
you want rather than the whole data step. Then embed the call to it
in the data step.
In your original example the name of the variable with the time (T)
did not vary. Why is it varying in your macro version?
%macro a(n);
%local j;
%do i=0 %to &n;
if T-&i > 0 then d&i= mwspread/((1+_mlibor)**(T-&i)); else d&i=0;
%end;
%mend;
data b;
set a;
by id_bb year month;
%a(125);
run;
Next exercise is it to eliminate the macro completely and just code it
using arrays.
On Feb 3, 3:07 pm, ChrisG <chris.godlew...@gmail.com> wrote:
> Hello all
>
> After spending a long time searching for a clue around here without
> success I am submitting you my (probably easy & dumb) problem
>
> Here is what works well with my data:
>
> data b; set a; by id_bb year month;
> if t > 0 then d0=mmwspread/((1+libor)**(t)); else d0=0;
> if t - 1 > 0 then d1=mmwspread/((1+libor)**(t-1));else d1=0;
> if t - 2 > 0 then d2=mmwspread/((1+libor)**(t-2));else d2=0;
> if t - 3 > 0 then d3=mmwspread/((1+libor)**(t-3));else d3=0;
> if t - 4 > 0 then d4=mmwspread/((1+libor)**(t-4));else d4=0;
> if t - 5 > 0 then d5=mmwspread/((1+libor)**(t-5));else d5=0;
> if t - 6 > 0 then d6=mmwspread/((1+libor)**(t-6));else d6=0;
> run;
>
> now the issue is that in the initial data i had t = 1 to 7 (t is for a
> time period)
>
> now in the big dataset i have t = 1 to 126 !!!
>
> so instead of typing 125 lines of sas code i tried to do a macro
>
> something like this:
>
> %macro a;
> %do t=1 %to 126;
> %do i=0 %to 125;
> data b; set a; by id_bb year month;
> if &t-&i > 0 then d&i= mwspread/((1+_mlibor)**(&t-&i)); else d&i=0;
> output;
> %end;
> output;
> %end;
> %mend;
> %a;
>
> the problem is that this macro is not "appending" the d&i variable but
> puts the newest value of d&i in the palce of the old one
> at the end i get just the d125 in the data
> but i want to have the d0 until d125
>
> could you help me out please ?
>
> thanks in advance
> Cheers
> CG
|