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.
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
>data two (drop=i j);
>do j=month(start) to month(end)+(year(end)-year(start))*12;
>On 8/31/05, Venky Chakravarthy <firstname.lastname@example.org> 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.
>> 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
>> 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 ;