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 (January 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 11 Jan 2008 12:26:34 -0800
Reply-To:     "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Subject:      Re: data manipulation
In-Reply-To:  <251946.53709.qm@web7807.mail.in.yahoo.com>
Content-Type: text/plain; charset="us-ascii"

Use a normal SET statement to read an observation each iteration of the DATA step. Within the current iteration, use a DO loop with a SET/KEY= statement to quickly run the chain (e.g., from 1 to 3 to 5 to 8). When you reach the end of the chain, OUTPUT the final value along with an incremented counter (such as _n_ from the normal SET). This will produce observations of the form 1 8 1 2 4 2 3 8 3 5 8 4 7 9 5

To get rid of the intermediate observations, sort this output by new and counter and then keep only the observations where first.new is 1. You could even DROP the counter at this point if you want.

-----Original Message----- From: riya j [mailto:riyaa_j17@YAHOO.CO.IN] Sent: Thursday, January 10, 2008 7:43 PM To: SAS-L@LISTSERV.UGA.EDU Subject: data manipulation

Hi,

I'm trying this for a few days now, but I seem to be going nowhere. I was wondering if anyone could help me code the logic .

My input data looks something like this

old new 1 3 2 4 3 5 5 8 7 9

so basically, here old and new are old and new ids or accounts or whatever. The first row means that the old id 1 is changed to a new id 3. Now the id 3 is now 5, as seen in the third obs. This 5 id becomes 8 as per observation number 4. So in the output dataset, i should get only one row with the old id as 1 and the new id as 8. So basically I'm compressing the conversion of ids and getting rid of the intermediate conversions. The second and fifth observation will remain unchanged. The output data should look something like this

old new 1 8 2 4 7 9

In the above example I showed only 3 intermediate conversions, there could be many.


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