|
Siddharth,
I think requiring a multi-dimensional array is overcomplicating it, and I
don't think your desired resulting file is sufficiently analyzable, but
here is one such solution:
data have;
input Var1 $ Var2-Var5;
cards;
A 50 75 60 80
A 90 100 50 98
B 2 5 6 7
B 50 5 6 2
C 2 3 10 10
C 5 10 15 20
;
data want (keep=var1-var5);
retain Var1;
array inVars(*) Var2-Var5;
array vars(2,4);
retain vars;
set have;
by Var1;
output;
if first.Var1 then do i=1 to 4;
Vars(1,i)=inVars(i);
end;
else if last.Var1 then do;
Var1="Abs_Diff";
do i=1 to 4;
Vars(2,i)=inVars(i);
inVars(i)=abs(Vars(2,i)-Vars(1,i));
end;
output;
end;
run;
HTH,
Art
--------
On Thu, 2 Apr 2009 21:59:57 -0400, Siddharth Gilani
<siddharth_gilani@YAHOO.COM> wrote:
>Hi Guys, I have the following situation and I was wondering if someone
>could help me understand how to solve it using a 2-dimensional array
>
>I have the following partial structure within a dataset:
>
>Var1 Var2 Var3 Var4 Var5
>
>A 50 75 60 80
>A 90 100 50 98
>B 2 5 6 7
>B 50 5 6 2
>C 2 3 10 10
>C 5 10 15 20
>
>I want to find the differnce in Var2-Var5 by Var1 and create another
>record with the difference:
>
>So for the first case the output should be something like:
>
>Var1 Var2 Var3 Var4 Var5
>
>A 50 75 60 80
>A 90 100 50 98
>ABS Diff 40 25 10 18
>
>and so on...
>
>I have 30 variables in the dataset excluding var1.
>
>Will greatly appreciate your help.
>
>Thanks!!
|