1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| data test;input var1 var2;
cards;
10 60
-100 60
50 100
-30 70
10 60
-70 60
50 100
-30 70
10 60
-70 60
50 100
-30 70
10 60
-70 60
50 100
10 60
70 60
25 100
;run;
%macro test;
proc sql noprint;
select sum(Var1) into : Sum from test;
%if &sum le 0 %then %do;
proc iml;
use test;
read all var {Var1 Var2} into X;
Y=X||j(nrow(X),2,0);
Y[1,3]=%sysevalf(-1*&sum);
Y[1,4]=Y[1,3]-Y[1,2];
do i=2 to nrow(Y);
Y[i,3]=Y[i-1,4]; Y[i,4]=Y[i,3]-Y[i,2];
end;
CREATE Test1 FROM Y[colname={"Var1","Var2","Test1","Test2"}] ;
APPEND FROM Y;
CLOSE test1;
quit;
%end;
data test1 (drop = test1 test2);
set test1;
if test1>0 then do;
if test2>=0 then do;
Var1=Var1+Var2; Var2=0;
end;
else do;
Var1=Var1+test1;
Var2=Var2-test1;
end;
end;
run;
%mend;
%test; |
Partager