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 (November 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 24 Nov 2008 13:12:06 +0530
Reply-To:     Anindya Mozumdar <anindya.lugbang@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Anindya Mozumdar <anindya.lugbang@GMAIL.COM>
Subject:      Re: Problem with counter in data step
Comments: To: Van Nguyen <nana.nguyen@gmail.com>
In-Reply-To:  <4de0543f0811232242jefa9d8fy7b7ea405be468b80@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

> In summary, if I sort the dataset by id and visitdate and use the previous > visit num and increment by .1 for the Temp Visit. > I have problem with the ID 02 since it has 2 dates for Temp Visit.

Is this what you want -

data visits; infile datalines dsd dlm = ' ' missover; input id :$2. visit :$15. visitnum :8. visitdate :date9.; format visitdate date9.; datalines; 01 visit1 1 08Jul2008 01 visit1 1 08Jul2008 01 "Temp visit" . 09Jul2008 01 "Temp visit" . 09Jul2008 02 visit2 2 08Jul2008 02 visit2 2 09Jul2008 02 "Temp visit" . 12Aug2008 02 "Temp visit" . 12Aug2008 02 "Temp visit" . 15Aug2008 02 "Temp visit" . 15Aug2008 ; run;

proc sort data = visits; by id visitdate; run;

data visits2; set visits; by id; retain lastvisitnum lastvisitdate; if missing(visitnum) then do; if visitdate = lastvisitdate then visitnum = lastvisitnum; else visitnum = lastvisitnum + 0.1; end; lastvisitnum = visitnum; lastvisitdate = visitdate; drop lastvisitnum lastvisitdate; run;

-- Anindya Mozumdar http://www.anindyamozumdar.com


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