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 (December 1996, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 17 Dec 1996 13:57:18 +0500
Reply-To:     Bernard Tremblay <bernard@CAPITALE.QC.CA>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Bernard Tremblay <bernard@CAPITALE.QC.CA>
Subject:      Re: Re[2]: Add Calendar Year to Any Date
Comments: To: whitloi1@westatpo.westat.com
Comments: cc: bernard@pollux.BITNET

Ian, I guess you missed a couple of message in the thread. Here there are:

#1 -------------------------------------------------------------------------------- A message from me explaining that the last piece of code didn't work for the 29th of february. -------------------------------------------------------------------------------- #2 ------------------------------------------------------------------------------- Another message from me giving a fix by verifying first if the date is the 29th of february. ------------------------------------------------------------------------------ #3 ------------------------------------------------------------------------------- A very nice macro that fixed the problem, (not by me!)

----- Begin Included Message -----

From owner-sas-l@UGA.CC.UGA.EDU Fri Dec 13 09:43 EST 1996 Date: Thu, 12 Dec 1996 16:45:50 -0500 From: David Cuthbertson <david@DAISY.MOFFITT.USF.EDU> Subject: Re: Add Calendar Year to Any Date To: Multiple recipients of list SAS-L <SAS-L@UGA.CC.UGA.EDU>

Following is the macro Iuse to handle adding weeks, months and years to a SAS date value:

%macro timeup(date,num,interval); %if %upcase(&interval)=MONTH %then %do; intnx('month',&date,&num)+min(intnx('month',intnx('month',&date,&num),1)-intnx('month',intnx('month',&date,&num),0), day(&date)-1) %end; %if %upcase(&interval)=YEAR %then %do; intnx('month',intnx('year',&date,&num),month(&date)-1)+min(intnx('month',intnx('month',intnx('year',&date,&num),month(&date)-1),1)-intnx('month',intnx('month',intnx('year',&date,&num),month(&date)-1),0), day(&date)-1) %end; %if %upcase(&interval)=WEEK %then %do; intnx('week',&date,&num)+1 %end; %mend;

---------------------------------------------------------------------- David Cuthbertson, M.S. desk: (813) 632-1326 Biostatistician/ fax: (813) 632-1334 Associate in Pediatrics Moffitt Cancer Center at the University of South Florida email: ddcuthbertson@moffitt.usf.edu 12902 Magnolia Drive Tampa, FL 33612 ----------------------------------------------------------------------

----- End Included Message -----

-------------------------------------------------------------------------------- >>>From whitloi1@westatpo.westat.com Tue Dec 17 13:27 EST 1996 >>>From: whitloi1@westatpo.westat.com >>>Date: Tue, 17 Dec 96 13:22:54 EDT >>>Encoding: 128 Text >>>To: Bernard Tremblay <bernard@capitale.qc.ca> >>>Subject: Re[2]: Add Calendar Year to Any Date >>> >>> Bernard, >>> >>> I been swindled. >>> >>> 23 data _null_; >>> 24 date1='29feb96'd; >>> 25 format date1 date2 date9.; >>> 26 date2=mdy(month(date1),day(date1),year(date1)+1); >>> 27 put date1= date2= ; >>> 28 stop; >>> 29 run; >>> >>> NOTE: Invalid argument to function MDY at line 26 column 10. >>> DATE1=29FEB1996 DATE2=. >>> DATE1=29FEB1996 DATE2=. _ERROR_=1 _N_=1 >>> NOTE: Mathematical operations could not be performed at the following >>> places. The results of >>> the operations have been set to missing values. >>> Each place is given by: (Number of times) at (Line):(Column). >>> 1 at 26:10 >>> NOTE: The DATA statement used 0.22 seconds. >>> >>> Ian Whitlock >>> >>>______________________________ Reply Separator _________________________________ >>>Subject: Re: Add Calendar Year to Any Date >>>Author: Bernard Tremblay <bernard@CAPITALE.QC.CA> at internet-e-mail >>>Date: 12/12/96 4:12 PM >>> >>> >>>Hi, >>> I liked this piece of code so much that I tried it. But to my >>>stupefaction, it didn't work exactly like I expected... Look to this >>>sas log: >>> >>>2267 data _null_; >>>2268 date1=date(); >>>2269 format date1 date2 date9.; >>>2270 date2=(intnx('year',date1,+1))+(date1-intnx('year',date1,0)); >>>2271 put date1= date2= ; >>>2272 stop; >>>2273 run; >>> >>>DATE1=12DEC1996 DATE2=13DEC1997 >>>NOTE: DATA statement used: >>> real time 1.381 seconds >>> cpu time 0.099 seconds >>> >>> OOPS... 1996 is bissextile! >>> >>> So one should be cautious with that arithmetic because the number >>>of the day is shifted by one for all days after the 29th of february when >>>it is a bissextile year! >>> >>>The only workaround I could figure that did not implied calculation >>>to figure out if the year is bissextile is the following: >>> >>>2281 data _null_; >>>2282 date1=date(); >>>2283 format date1 date2 date9.; >>>2284 date2=mdy(month(date1),day(date1),year(date1)+1); >>>2285 put date1= date2= ; >>>2286 stop; >>>2287 run; >>> >>>DATE1=12DEC1996 DATE2=12DEC1997 >>>NOTE: DATA statement used: >>> real time 1.341 seconds >>> cpu time 0.092 seconds >>> >>>Not as nice as the first attempt, but it works in all cases. >>> >>> I hope put some light on that subject, >>> >>> Bernard Tremblay >>> >>> >>> \\\|/// >>> \\ - - // >>> ( @ @ ) >>>+------oOOo-(_)-oOOo----------+---------------------------------+ >>>| Bernard Tremblay | Bureau: (418) 646-2401 | >>>| La Capitale | Maison: (418) 878-4447 | >>>| |Internet: bernard@capitale.qc.ca | >>>| | bertrem@quebectel.com | >>>+---------------Oooo----------+---------------------------------+ >>> oooO ( ) >>> ( ) ) / >>> \ ( (_/ >>> \_) >>> >>> >>> >>> >>> >>>>>>From owner-sas-l@UGA.CC.UGA.EDU Thu Dec 12 15:43 EST 1996 >>>>>>Encoding: 26 TEXT >>>>>>Date: Thu, 12 Dec 1996 12:39:00 PST >>>>>>From: "Connolly, Roger" <rconn@ACCX.GHC.ORG> >>>>>>Subject: Re: Add Calendar Year to Any Date >>>>>>To: Multiple recipients of list SAS-L <SAS-L@UGA.CC.UGA.EDU> >>>>>> >>>>>>easy >>>>>> >>>>>>date2=(intnx('year',date1,+1))+(date1-intnx('year',date1,0)) >>>>>> ---------- >>>>>>From: owner-sas-l >>>>>>To: Multiple recipients of list SAS-L >>>>>>Subject: Add Calendar Year to Any Date >>>>>>Date: Thursday, December 12, 1996 2:16PM >>>>>> >>>>>>Hi folks, >>>>>> >>>>>>I am sure if I spent more time than I have at my disposal >>>>>>that I could figure this out(which I may have to do). >>>>>> >>>>>>Does anyone know how to get from i.e >>>>>> >>>>>>12/22/95 to 12/22/96 >>>>>>1/1/92 to 1/1/93 >>>>>>4/12/94 to 4/12/95 >>>>>> >>>>>>? >>>>>> >>>>>>TIA, >>>>>> >>>>>>Todd Weiss >>>>>> >>> >>>


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