LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: Df Ss <tggsun@YAHOO.COM>

On Mon, 16 May 2005 13:01:46 -0700, df ss <tggsun@YAHOO.COM> wrote:

>Hello SAS-L, >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 >and k2. >K1=compress(x1||x2); >K2=compress(x3||x4); >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 > >data b; >set a; >format k1-k2 $2.; >array new k1 -- k2; >array old x1 -- x4; >do j=1 to 2; >do i=1 to 4; >new(j)=compress(old(i)||old(i+1)); >end; >end; >run; > >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.

Hi, HHH,

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:

data b; set a; k1 = compress(x1 || x2); k2 = compress(x3 || x4); run;

If you have to use a do-loop, then remember that you just want to generate two variables only.

data b; set a; 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)); end; run;

But, isn't the above more complicated? HTH.

Cheers, Chang


Back to: Top of message | Previous page | Main SAS-L page