X1 | X2 | X3 | X4 | X5 |
---|---|---|---|---|
-10 | -5 | 50 | 50 | 100 |
3 | 23 | 42 | -1 | 23 |
1 | -5 | -7 | 44 | 12 |
Bascially i want to perform calculation that allocates the negative values to the cells with the positive values in proportion to the split of the positive values.
So the above table would become:
X1 | X2 | X3 | X4 | X5 |
---|---|---|---|---|
0 | 0 | =50+(-15)*(50/200) | =50+(-15)*(50/200) | =100+(-15)*(100/200) |
To achive this i need to sum the negative values, the posive values and then apply a condition formula like if X1 <0 then X1 =0; else X1 = X1 + (sumNeg)*(X1)/(sumPos);
or something like that
Is this easy to do?
data want(keep=x1-x5);
set have;
array x{*} x1-x5;
sum_neg=0;
sum_pos=0;
do i=1 to dim(x);
if x{i}<0 then sum_neg+x{i};
else sum_pos+x{i};
if x{i}<0 then x{i}=0;
end;
do i=1 to dim(x);
x{i} = x{i} + sum_neg*x{i}/sum_Pos;
end;
run;
data want(keep=x1-x5);
set have;
array x{*} x1-x5;
sum_neg=0;
sum_pos=0;
do i=1 to dim(x);
if x{i}<0 then sum_neg+x{i};
else sum_pos+x{i};
if x{i}<0 then x{i}=0;
end;
do i=1 to dim(x);
x{i} = x{i} + sum_neg*x{i}/sum_Pos;
end;
run;
Thank you
data have;
input var1 var2 var3 var4 var5;
cards;
-10 -5 50 50 100
3 23 42 -1 23
1 -5 -7 44 12
;
run;
%let howmany = 5;
%macro want(howmany);
%IF &howmany GT 0 %THEN
%DO;
data want;
set have;
%do j=1 %to &howmany;
if var&j. lt 0 then
var&j.=0;
else var&j.=var&j.+(-15)*(var&j./200);
%end;
run;
%end;
%mend want;
%want(5)
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.