The following code is executed and the result is wrong. When the first condition is verified the code don't work correctly. The lag1 it remains as missing when the value should be 3... Thanks for help me.
DATA VALUES;
INPUT VAL caract$ var1 var2;
DATALINES;
1 a 12 0
1 c 0 4
1 c 3 2
2 a 3 2
2 b 15 16
2 b 4 1
3 a 12 13
3 c 12 13
4 c 14 15
5 b 14 0
6 b 14 15
7 a 12 15
7 c 12 15
8 c 14 15
9 c 14 5
10 c 13 7
;
RUN;
%macro lag_var(dataset, lag);
data &dataset&lag;
set &dataset;
by VAL;
%do i=0 %to &lag;
if caract eq 'b' then
lag&i=lag&i(var1);
else lag&i = lag&i(var2);
%end;
if first.VAL then do;
count=0;
%do i=1 %to &lag;
lag&i=.;
%end;
end;
count+1;
%do i=1 %to &lag;
if (not first.VAL and count<=&i) then do;
lag&i=.;
end;
%end;
maxi = max(of lag1 - lag&lag);
run;
%mend lag_var;
%lag_var(VALUES,3);
Aucun commentaire:
Enregistrer un commentaire