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 (May 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 19 May 2008 10:07:32 -0400
Reply-To:     Arthur Tabachneck <art297@NETSCAPE.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Arthur Tabachneck <art297@NETSCAPE.NET>
Subject:      Re: Summing months in dates
Comments: To: susana.urbano@GMAIL.COM

Nanita,

Your code appears to work as written. It might be that your Prazo variable has leading or trailing blanks and, if so, you could specify it as trim(Prazo) or trim(left(Prazo)) in your if statements.

Alternatively, you could just capture the first and 2nd+3rd characters from Prazo and avoid the if statements altogether. For example:

data txcp_copy; *SET mylib.txcurtoprazo; input Prazo $3. @5 Data_valor date9.; format Data_valor End_Date End_Date2 date9.; IF Prazo='D01' THEN DO; End_Date=intnx('day',Data_valor,1,'s'); END; else IF Prazo='D07' THEN DO; End_Date=intnx('day',Data_valor,7,'s'); END; else IF Prazo='D14' THEN DO; End_Date=intnx('day',Data_valor,14,'s'); END; else IF Prazo='M01' THEN DO; end_date=intnx('month',Data_valor, 1,'s' ); END; type=substr(prazo,1,1); if type eq 'D' then type='day'; else if type eq 'M' then type='month'; period=substr(prazo,2,2); end_date2=intnx(type,Data_valor, period,'s' ); cards; D14 14MAY1999 M01 10APR2002 M01 29JAN2007 D01 01JAN2007 D07 30DEC2007 ;

HTH, Art --------- On Mon, 19 May 2008 06:31:41 -0700, Nanita <susana.urbano@GMAIL.COM> wrote:

>On 19 Maio, 13:38, peter.crawf...@BLUEYONDER.CO.UK (Peter Crawford) >wrote: >> On Mon, 19 May 2008 03:45:35 -0700, RolandRB <rolandbe...@HOTMAIL.COM> >> wrote: >> >> >> >> >On May 19, 12:27 pm, Nanita <susana.urb...@gmail.com> wrote: >> >> Hi there, >> >> >> I'me havind some trouble summing some dates. >> >> >> I have a table with a column with Begin_Date and another colunm with >> >> Maturity_Lenght. >> >> >> I need to create another column with the End_Date, by adding the >> >> Maturity_Lenght to the Begin_Date. >> >> >> Begin_Date Maturity_Lenght (month) End_Date >> >> >> 02-05-2008 1 >> >> 02-06-2008 >> >> >> 05-05-2008 3 >> >> 05-08-2008 >> >> ..... >> >> >> How can I do that? >> >> >> Thank you so much. >> >> >In the following case I am adding 3 months to dt to get dt2. >> >> >13 data _null_; >> >14 format dt dt2 date9.; >> >15 dt="05jun2008"d; >> >16 dt2=mdy(month(dt)+3,day(dt),year(dt)); >> >17 put dt2=; >> >18 run; >> >> >dt2=05SEP2008 >> >NOTE: DATA statement used: >> > real time 0.00 seconds >> > cpu time 0.00 seconds >> >> I wouldn't recommend this approach that adds increments to the >> parameters of the mdy() function, because not only is there the >> risk of crossing year-ends but SAS has built in a solution using >> the INTNX() function. >> Introduced with SAS9 (iirc) the variation of the 4th parameter >> of INTNX() to have a value of 'S' for "same-day" is really neat. >> >> Then if the maturity_length is M03 (3 months), >> new_date = intnx( 'month', old_date, 3, 's' ); >> If instead the maturity_length should be D14 (14 days) >> new_date = intnx( 'day', old_date, 14, 's' ); >> It even supports week intervals, like W02 (2 weeks) >> new_date = intnx( 'week', old_date, 2, 's' ); >> >> DAY intervals coincide with the underlying date-system so are a bit >> over-kill, but that enables a single approach to the solution. >> >> It should be simple enough to convert "maturity_length" code into >> the first and third parameters of INTNX(). >> >> PeterC > >Hi, I've tried again... and I really don't know what I did wrong... > >data mylib.txcp_copy; >SET mylib.txcurtoprazo; >IF Prazo='D01' THEN DO > End_Date=intnx('day',Data_valor,1,'s'); > END; >IF Prazo='D07' THEN DO > End_Date=intnx('day',Data_valor,7,'s'); > END; >IF Prazo='D14' THEN DO > End_Date=intnx('day',Data_valor,14,'s'); >END; >IF Prazo='M01' THEN DO > >end_date=intnx('month',Data_valor, 1,'s' ); > > END; >run;


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