Date: Wed, 31 Aug 2005 15:43:49 -0400 Venky Chakravarthy "SAS(r) Discussion" Venky Chakravarthy Re: years and months from a time period To: Junwu Shen

Sure, there is a way of capturing the year if you make your own assumptions. In your solution the value of year corresponds to the START variable for some observations and to the END variable for others. Perhaps, that is what is truly required. However, that was not articulated well as part of the original specs.

Venky Chakravarthy

On Wed, 31 Aug 2005 15:07:16 -0400, Junwu Shen <jxs705@GMAIL.COM> wrote:

>For the case where the starting year is different from ending year, >this code should work: > >data one ; > input Id start : mmddyy10. end : mmddyy10. ; > cards ; >1 06/12/2000 03/15/2003 >run ; >data two (drop=i j); >set one; >do j=month(start) to month(end)+(year(end)-year(start))*12; >i=ceil(j/12)-1; >month=j-12*i; >year=year(start)+i; >output; >end; >run; > >proc print; >run; >On 8/31/05, Venky Chakravarthy <swovcc@hotmail.com> wrote: >> On Wed, 31 Aug 2005 10:43:44 -0700, hmekouar@HOTMAIL.COM wrote: >> >> >Hi everyone, >> >I am trying to create unique combinations of years and months from time >> >periods. For instance, let's say I have a record: >> >Id start end >> >1 01/12/2000 03/15/2000 >> > >> >I want the dataset to look like: >> > >> >Id month year >> >1 1 2000 >> >1 2 2000 >> >1 3 2000 >> > >> >Anyone wants to share a piece of code. I appreciate any help on that. >> >Thanks so much. >> >> Hopefully, your sample of 1 observation represents your true data well. Are >> all observations guaranteed to have the same year for both start and end? >> Do you have more records for each ID? If yes, do they encompass a >> previously declared start or end and how would you like to treat them? >> Discounting the possibility of any of these concerns, here is a simple >> solution. >> >> >> data have ; >> input Id start : mmddyy10. end : mmddyy10. ; >> cards ; >> 1 01/12/2000 03/15/2000 >> run ; >> >> data want ; >> set have ; >> do month = month(start) to month(end) ; >> year = year(end) ; >> output ; >> end ; >> drop start end ; >> run ; >>

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