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 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 10 Nov 2007 15:07:05 -0800
Reply-To:     Patrick <patrick.matter@GMX.CH>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Patrick <patrick.matter@GMX.CH>
Organization: http://groups.google.com
Subject:      Re: DATDIF with multiple observations
Comments: To: sas-l@uga.edu
In-Reply-To:  <200711102026.lAAKM037027581@mailgw.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

Then you should use the good old lag function. By the way: I defined the first range of the format wrong (shame on me!). Corrected now in the code below. Hope that solves your problem. Patrick

P.S: If you browse this group a bit looking for "lag" you will find a lot of similar questions to yours and lots of different solutions as well.

proc format; value periods 1-29 = 'Less than 30 days' 30 = 'Thirty days' 31-high = 'More than thirty days' 0 = 'n/a'; run; Data indat; infile datalines firstobs=1 pad; input @1 ID $2 @5 visit MMDDYY8.; /*other variables just junk to this question so left out*/ format visit mmddyy10.; datalines; 01 03/10/04 01 05/25/04 01 09/16/04 02 02/12/04 02 02/13/04 02 03/14/04 02 05/15/04 03 01/01/04 03 02/12/04 03 07/06/04 04 06/16/04 04 07/10/04 04 07/21/04 04 08/15/04 04 09/27/04 ; proc sort data=indat; by id visit; run; data outdat; set indat; by id; format datdif periods.; datdif=visit-lag(visit); if first.id then datdif=0; run; proc print data=outdat; run;


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