Date: Mon, 16 May 2005 16:15:59 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: array question
On Mon, 16 May 2005 13:01:46 -0700, df ss <tggsun@YAHOO.COM> wrote:
>I have a data set like that
>x1 x2 x3 x4
>1 2 3 4
>5 6 7 8
>I would like to combind them into two new variables k1
>the final data set should be like that
>x1 x2 x3 x4 k1 k2
>1 2 3 4 12 34
>5 6 7 8 56 78
>I want to write a macro to do that
>format k1-k2 $2.;
>array new k1 -- k2;
>array old x1 -- x4;
>do j=1 to 2;
>do i=1 to 4;
>But the result is not right, they only combind the x3
>and x4 into k1 and k2.
>I want to know the reason for that.
You are not writing a macro. You could, but I don't think it is neccessary.
I am not sure even the do-loops are neccessary either. I would do, simply:
k1 = compress(x1 || x2);
k2 = compress(x3 || x4);
If you have to use a do-loop, then remember that you just want to generate
two variables only.
length k1-k2 $2.;
array new k1 -- k2;
array old x1 -- x4;
drop i j;
do j=1 to 2;
i = 2 * (j-1) + 1;
new(j)=compress(old(i) || old(i+1));
But, isn't the above more complicated? HTH.