From: Ya Huang on
Happy new year Venkey,

Your code may have problem (depends on what the original poster wants).
I changed the input data, so that there is a missing after the first
non-missing:

2 20060502
2 20060627
3 .
3 .
3 20070101
3 20070102
3 . <- missing after first nonmissing;
3 20070102
run ;

The result is like this:

2 20060627
3 20070101
3 20070101
3 20070101
3 20070102
3 20070101 <- I guess it would make more sense if this is 20070102 ?
3 20070102



On Tue, 2 Jan 2007 12:02:36 -0500, Venky Chakravarthy <swovcc(a)HOTMAIL.COM>
wrote:

>On Tue, 2 Jan 2007 00:38:52 -0800, deepalipowale(a)GMAIL.COM wrote:
>
>>hi all ,
>>
>>i want to retained FIRST non-missing values.
>>e.g. ORIGINAL DATASET
>>
>>ID DATE
>>1 20051018
>>1 20051213
>>2
>>2 20060502
>>2 20060627
>>
>>I want it like this:
>>
>>REQUIRED
>>
>>ID DATE NEW_DATE
>>1 20051018 20051018
>>1 20051213 20051018
>>2 20060502
>>2 20060502 20060502
>>2 20060627 20060502
>
>I am assuming that within an ID, once a date becomes non-missing it is
>always present after that. Note that your example is expanded slightly to
>accommodate more than one missing date within an ID but it is consecutive.
>Also note that if you have missing dates between valid dates it will be
>filled with the first non-missing date value for that ID.
>
>The modification to the classical DoW stops processing the first SET after
>the first non-missing date observation is read. That is all that is needed
>from it. The second SET outputs all observations but only after it fills
>missing DATE values with FIRSTDATE.
>
>data withmissing ;
> input ID DATE : yymmdd. ;
> format date yymmddn8. ;
> cards ;
>1 20051018
>1 20051213
>2 .
>2 20060502
>2 20060627
>3 .
>3 .
>3 20070101
>3 20070102
>run ;
>
>data filled ;
> do until (first.id) ;
> set withmissing (where = (firstdate^=.) rename = (date=firstdate));
> by id ;
> end ;
> do until (last.id) ;
> set withmissing ;
> by id ;
> if missing(date) then date = firstdate ;
> output ;
> end ;
> drop firstdate ;
>run ;
>
>Venky Chakravarthy
From: Venky Chakravarthy on
Hi Ya,

A very happy new year to you too.

You are indeed correct that the code would have problems with the example
that you presented. Those were exactly my thoughts when I first looked at
the problem. I tried to address those points in my first paragraph which
stated:

>>Also note that if you have missing dates between valid dates it will be
>>filled with the first non-missing date value for that ID.

But also bear in mind that the original poster's request was:

>>>i want to retained FIRST non-missing values.

So the burden is on the original poster to clarify how he/she wants it to
be processed when there is a missing value between valid values. Would that
still need to be filled with the FIRST non-missing value or the NEXT non-
missing value?

Regards,

Venky

On Tue, 2 Jan 2007 12:20:26 -0500, Ya Huang <ya.huang(a)AMYLIN.COM> wrote:

>Happy new year Venkey,
>
>Your code may have problem (depends on what the original poster wants).
>I changed the input data, so that there is a missing after the first
>non-missing:
>
>2 20060502
>2 20060627
>3 .
>3 .
>3 20070101
>3 20070102
>3 . <- missing after first nonmissing;
>3 20070102
>run ;
>
>The result is like this:
>
> 2 20060627
> 3 20070101
> 3 20070101
> 3 20070101
> 3 20070102
> 3 20070101 <- I guess it would make more sense if this is 20070102 ?
> 3 20070102
>
>
>
>On Tue, 2 Jan 2007 12:02:36 -0500, Venky Chakravarthy <swovcc(a)HOTMAIL.COM>
>wrote:
>
>>On Tue, 2 Jan 2007 00:38:52 -0800, deepalipowale(a)GMAIL.COM wrote:
>>
>>>hi all ,
>>>
>>>i want to retained FIRST non-missing values.
>>>e.g. ORIGINAL DATASET
>>>
>>>ID DATE
>>>1 20051018
>>>1 20051213
>>>2
>>>2 20060502
>>>2 20060627
>>>
>>>I want it like this:
>>>
>>>REQUIRED
>>>
>>>ID DATE NEW_DATE
>>>1 20051018 20051018
>>>1 20051213 20051018
>>>2 20060502
>>>2 20060502 20060502
>>>2 20060627 20060502
>>
>>I am assuming that within an ID, once a date becomes non-missing it is
>>always present after that. Note that your example is expanded slightly to
>>accommodate more than one missing date within an ID but it is consecutive.
>>Also note that if you have missing dates between valid dates it will be
>>filled with the first non-missing date value for that ID.
>>
>>The modification to the classical DoW stops processing the first SET after
>>the first non-missing date observation is read. That is all that is needed
>>from it. The second SET outputs all observations but only after it fills
>>missing DATE values with FIRSTDATE.
>>
>>data withmissing ;
>> input ID DATE : yymmdd. ;
>> format date yymmddn8. ;
>> cards ;
>>1 20051018
>>1 20051213
>>2 .
>>2 20060502
>>2 20060627
>>3 .
>>3 .
>>3 20070101
>>3 20070102
>>run ;
>>
>>data filled ;
>> do until (first.id) ;
>> set withmissing (where = (firstdate^=.) rename = (date=firstdate));
>> by id ;
>> end ;
>> do until (last.id) ;
>> set withmissing ;
>> by id ;
>> if missing(date) then date = firstdate ;
>> output ;
>> end ;
>> drop firstdate ;
>>run ;
>>
>>Venky Chakravarthy
From: "Howard Schreier <hs AT dc-sug DOT org>" on
On Tue, 2 Jan 2007 01:01:24 -0800, Mogens A. Krogh <MKROGH(a)DSR.KVL.DK> wrote:

>You could do something like this, if your data is sorted in ID DATE
>
>data test;
>input ID $ DATE ;
>cards;
>1 20051018
>1 20051213
>2 .
>2 20060502
>2 20060627
>;;
>run;
>data want;
>merge test test (rename=(date=_newdate) where=(_newdate ^= .));
>by ID;
>if first.id then newdate=_newdate;
>retain newdate;
>drop _:;
>run;

Or

data want;
do until(last.id);
set test
test(in=secondpass);
by ID;
if missing(new_date) then new_date = date;
if secondpass then output;
end;
run;

>
>regards
>Mogens A. Krogh
>DVM, PhD-student
>Faculty of Life Sciences
>University of Copenhagen, Denmark
>
>
>deepalipowale(a)gmail.com skrev:
>> hi all ,
>>
>> i want to retained FIRST non-missing values.
>> e.g. ORIGINAL DATASET
>>
>> ID DATE
>> 1 20051018
>> 1 20051213
>> 2
>> 2 20060502
>> 2 20060627
>>
>> I want it like this:
>>
>> REQUIRED
>>
>> ID DATE NEW_DATE
>> 1 20051018 20051018
>> 1 20051213 20051018
>> 2 20060502
>> 2 20060502 20060502
>> 2 20060627 20060502