@Ksharp Sorry to bother you again, as I have mentioned this code is giving the exact output but there are still two issues. First one is that if X1=1 more than one time for an ID, "Want" column is not equal to "X" in such a case. My objective is that for the very first time as X1=1 for an ID, remaining all observations of Want should be equal to X irrespective of "X1=1" occurs twice, thrice or even more than that in a particular ID. Secondly, I am looking for Want column where "want=x" NOT from the observation where X1=1 but from the START of the YEAR in which X1=1 for a specific ID. For example, in my data set "have" for ID1 X1=1 in a month of year 2005 (07/31/2005). So now "want=X" should be starting from the very first date of this year i.e. 01/31/2005 and should then continue till 10/31/2008. Please see below the output required: data want;
input ID Date_month X X1 Want ;
datalines; 1 12/31/2001 1 0 0
1 01/31/2005 0 0 0
1 02/28/2005 1 0 1
1 03/31/2005 1 0 1
1 04/30/2005 0 0 0
1 05/31/2005 0 0 0
1 06/30/2005 0 0 0
1 07/31/2005 1 1 1
1 08/31/2005 0 0 0
1 09/30/2005 1 0 1
1 10/31/2005 1 0 1
1 11/30/2005 0 1 0
1 12/31/2005 0 0 0
1 01/31/2008 1 0 1
1 02/28/2008 1 0 1
1 03/31/2008 0 0 0
1 10/31/2008 1 0 1
2 01/31/2004 1 0 1
2 02/28/2004 1 1 1
2 03/31/2004 0 1 0
2 08/31/2004 0 0 0
2 11/30/2004 1 0 1
2 12/31/2004 1 0 1;
run; I will be thankful for your guidance.
... View more