From: deepalipowale on 2 Jan 2007 03:38 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
From: Romel on 2 Jan 2007 03:46 Hi, In this item "2 20060502" how did you define the newdate should be 20060502? Regards Romel 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
From: Mogens A. Krogh on 2 Jan 2007 04:01 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; 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
From: sudhir ahuja on 2 Jan 2007 04:36 hi, this is the way that i know data have; have; input ID $ DATE ; cards; 1 20051018 1 20051213 2 . 2 20060502 2 20060627 ; run; proc summary data = have nway missing; class id; var date ; output out = summary min = ; run; ******* data was already sorted so i didnt sort it before merging*********; data have_final(keep = keep = id date new_date); have_final(keep = keep = id date new_date); merge have summary(rename = (date = new_date) ); by id; run; cheers On 1/2/07, deepalipowale(a)gmail.com <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 > -- sudhir ahuja
From: Venky Chakravarthy on 2 Jan 2007 12:02 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
|
Next
|
Last
Pages: 1 2 Prev: SAS message Log: Generic critical error. Next: proc surveyselect problem |