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 (February 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 5 Feb 2004 11:48:30 -0500
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: create a new variable that indicate a change

Try this.

data with_changes; do i = 1 by 1 until(last.id); drop i; set test; by id; if i=1 then start = amount; drop start; end; change_in_amount = amount - start; run;

Result:

change_ Obs ID AMOUNT in_amount

1 10001 3000 1000 2 10002 3000 500 3 10003 1000 0

By including a DATA step and data lines to load the test data, you made it very easy to work with this problem.

If you had also included a corresponding example of output, there would be less variation in the responses based on different interpretations.

On Thu, 5 Feb 2004 10:35:54 -0500, Jesper Nyholm <jesper_nyholm@POST.TELE.DK> wrote:

>/*** >Hi >Can anybody tell me how to create a new variable that indicate a change >in amount for every id? >***/ >DATA TEST; > INPUT ID 1-5 AMOUNT 7-11; >DATALINES; >10001 2000 >10001 2000 >10001 3000 >10002 2500 >10002 3000 >10003 1000 >10003 1000 >10003 1000 >10003 2000 >10003 1000 >;


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