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 2002, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 10 Jan 2002 11:01:45 -0500
Reply-To:     "Chakravarthy, Venky" <Venky.Chakravarthy@PFIZER.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Chakravarthy, Venky" <Venky.Chakravarthy@PFIZER.COM>
Subject:      Re: RETAIN-Statement
Comments: To: Sebastian Hein <heinseb@UNI-FREIBURG.DE>
Content-Type: text/plain; charset="iso-8859-1"

My first solution was correct without the BY. Should not have posted the second message at all. While in general it is considered bad practice to not use a BY statement in a merge, in this case it takes advantage of the fact that the MERGE is allowed without a BY.

Due apologies for the confusion and please disregard my SECOND message correcting my first.

Kind Regards,

Venky #****************************************# # E-mail: venky.chakravarthy@pfizer.com # # swovcc@hotmail.com # # Phone: (734) 622-1963 # #****************************************#

-----Original Message----- From: Chakravarthy, Venky [mailto:Venky.Chakravarthy@PFIZER.COM] Sent: Thursday, January 10, 2002 9:36 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: RETAIN-Statement

The BY statement was missing, after the MERGE, in my earlier posting. Admittedly, a terrible thing to do. The following is the corrected code :

data w (drop = _y) ; merge q q (firstobs = 2 rename = (y = _y)) ; /* X was dropped in the earlier post */ by x ; /* This was left out in the earlier post */ z = y - _y ; run ;

Kind Regards,

Venky #****************************************# # E-mail: venky.chakravarthy@pfizer.com # # swovcc@hotmail.com # # Phone: (734) 622-1963 # #****************************************#

-----Original Message----- From: Chakravarthy, Venky [mailto:Venky.Chakravarthy@PFIZER.COM] Sent: Thursday, January 10, 2002 9:10 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: RETAIN-Statement

Sebastian,

Ian Whitlock demonstrated a technique where in you merging a data set with itself. The trick lies in using the FIRSTOBS= option. This will not work if you are trying to do this within groups. See below:

data q ; input x y ; cards ; 40 20.6 35 18.6 30 16.5 25 14.3 20 12.0 ; run ;

data w (drop = _y) ; merge q q (firstobs = 2 drop = x rename = (y = _y)) ; z = y - _y ; run ;

Kind Regards,

Venky #****************************************# # E-mail: venky.chakravarthy@pfizer.com # # swovcc@hotmail.com # # Phone: (734) 622-1963 # #****************************************#

-----Original Message----- From: Sebastian Hein [mailto:heinseb@UNI-FREIBURG.DE] Sent: Thursday, January 10, 2002 4:21 AM To: SAS-L@LISTSERV.UGA.EDU Subject: RETAIN-Statement

Dear users,

can anyone help me with the following problem? Having the following data set with two variables, I want to create a new variable z, which should contain values as indicated: z = y (of row 2) - y (of row 1). After several trial with the RETAIN didn't come up with useful results. Do you have any suggestions?

X Y Z 40 20.6 2.0 (20.6 - 18.6) 35 18.6 2.1 (18.6 - 16.5) 30 16.5 and so on... 25 14.3 20 12.0


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