From: drraju123 on 15 Dec 2009 07:56 Hi All, I have data have and i want to get data want. the logic is for the val1 to have the minimum value of val at a particular asm comparing with previous asm. data have; input sub asm val; datalines; 1 0 45 1 1 22 1 2 12 1 3 32 1 4 48 1 5 29 1 6 9 1 7 33 2 0 23 2 1 2 2 2 44 2 3 7 2 4 66 2 5 33 2 6 1 2 7 66 ; run; data want; input sub asm val1; datalines; 1 0 . 1 1 45 1 2 22 1 3 12 1 4 12 1 5 12 1 6 12 1 7 9 2 0 . 2 1 23 2 2 2 2 3 2 2 4 2 2 5 2 2 6 2 2 7 1 ; run; thanks
From: Joe Matise on 15 Dec 2009 09:47 Untested: data want; set have; by sub asm; lagval = lag(val); if first.sub then call missing(val); else val = min(val,lagval); run; On Tue, Dec 15, 2009 at 6:56 AM, drraju123 <drraju123(a)gmail.com> wrote: > Hi All, > > I have data have and i want to get data want. the logic is for the > val1 to have the minimum value of val at a particular asm comparing > with previous asm. > > data have; > input sub asm val; > datalines; > 1 0 45 > 1 1 22 > 1 2 12 > 1 3 32 > 1 4 48 > 1 5 29 > 1 6 9 > 1 7 33 > 2 0 23 > 2 1 2 > 2 2 44 > 2 3 7 > 2 4 66 > 2 5 33 > 2 6 1 > 2 7 66 > ; > run; > > data want; > input sub asm val1; > datalines; > 1 0 . > 1 1 45 > 1 2 22 > 1 3 12 > 1 4 12 > 1 5 12 > 1 6 12 > 1 7 9 > 2 0 . > 2 1 23 > 2 2 2 > 2 3 2 > 2 4 2 > 2 5 2 > 2 6 2 > 2 7 1 > ; > run; > > thanks >
From: Joe Matise on 15 Dec 2009 09:49 Hmm, I think this doesn't quite work because it doesn't carry forward the low one. You can use retain instead. data want; set have; by sub asm; retain oldval; if first.sub then call missing(val1); else val1 = min(val,val1); run; -Joe On Tue, Dec 15, 2009 at 8:47 AM, Joe Matise <snoopy369(a)gmail.com> wrote: > Untested: > data want; > set have; > by sub asm; > lagval = lag(val); > if first.sub then call missing(val); > else val = min(val,lagval); > run; > > > > On Tue, Dec 15, 2009 at 6:56 AM, drraju123 <drraju123(a)gmail.com> wrote: > >> Hi All, >> >> I have data have and i want to get data want. the logic is for the >> val1 to have the minimum value of val at a particular asm comparing >> with previous asm. >> >> data have; >> input sub asm val; >> datalines; >> 1 0 45 >> 1 1 22 >> 1 2 12 >> 1 3 32 >> 1 4 48 >> 1 5 29 >> 1 6 9 >> 1 7 33 >> 2 0 23 >> 2 1 2 >> 2 2 44 >> 2 3 7 >> 2 4 66 >> 2 5 33 >> 2 6 1 >> 2 7 66 >> ; >> run; >> >> data want; >> input sub asm val1; >> datalines; >> 1 0 . >> 1 1 45 >> 1 2 22 >> 1 3 12 >> 1 4 12 >> 1 5 12 >> 1 6 12 >> 1 7 9 >> 2 0 . >> 2 1 23 >> 2 2 2 >> 2 3 2 >> 2 4 2 >> 2 5 2 >> 2 6 2 >> 2 7 1 >> ; >> run; >> >> thanks >> > >
From: MAHESH KUMAR PEESARI on 15 Dec 2009 10:06 Hi, Plz check if this is meets your req... data have; input sub asm val; val1=lag(val); datalines; 1 0 45 1 1 22 1 2 12 1 3 32 1 4 48 1 5 29 1 6 9 1 7 33 2 0 23 2 1 2 2 2 44 2 3 7 2 4 66 2 5 33 2 6 1 2 7 66 ; run; proc sort data=have; by sub; run; data want1(drop=val1); set have; by sub; if first.sub=1 then val=.; else val=val1; run; proc print; run; On Tue, Dec 15, 2009 at 6:26 PM, drraju123 <drraju123(a)gmail.com> wrote: > Hi All, > > I have data have and i want to get data want. the logic is for the > val1 to have the minimum value of val at a particular asm comparing > with previous asm. > > data have; > input sub asm val; > datalines; > 1 0 45 > 1 1 22 > 1 2 12 > 1 3 32 > 1 4 48 > 1 5 29 > 1 6 9 > 1 7 33 > 2 0 23 > 2 1 2 > 2 2 44 > 2 3 7 > 2 4 66 > 2 5 33 > 2 6 1 > 2 7 66 > ; > run; > > data want; > input sub asm val1; > datalines; > 1 0 . > 1 1 45 > 1 2 22 > 1 3 12 > 1 4 12 > 1 5 12 > 1 6 12 > 1 7 9 > 2 0 . > 2 1 23 > 2 2 2 > 2 3 2 > 2 4 2 > 2 5 2 > 2 6 2 > 2 7 1 > ; > run; > > thanks > -- Thanks, Mahesh P *** FAILING TO PLAN IS PLANNING TO FAIL ***
From: Chang Chung on 15 Dec 2009 10:12 On Tue, 15 Dec 2009 04:56:55 -0800, drraju123 <drraju123(a)GMAIL.COM> wrote: .... >I have data have and i want to get data want. the logic is for the >val1 to have the minimum value of val at a particular asm comparing >with previous asm. Hi, To me, your description above indicates not lagging val at all. Below follows what your description says, not the example shows. Hope this helps a bit. Cheers, Chang data have; input sub asm val; datalines; 1 0 45 1 1 22 1 2 12 1 3 32 1 4 48 1 5 29 1 6 9 1 7 33 2 0 23 2 1 2 2 2 44 2 3 7 2 4 66 2 5 33 2 6 1 2 7 66 ; run; /* newVal has the minimum value of vals upto current obs^s within the current sub */ proc sort data=have; by sub asm; run; data want; if 0 then set have; /* to prep pdv */ newVal = .; do until (last.sub); set have; by sub asm; newVal = min(newVal, val); output; end; run; /* check */ proc print data=want; by sub; run; /* on lst sub=1 new Obs asm val Val 1 0 45 45 2 1 22 22 3 2 12 12 4 3 32 12 5 4 48 12 6 5 29 12 7 6 9 9 8 7 33 9 sub=2 new Obs asm val Val 9 0 23 23 10 1 2 2 11 2 44 2 12 3 7 2 13 4 66 2 14 5 33 2 15 6 1 1 16 7 66 1 */
|
Pages: 1 Prev: Sas DDE Excel Next: how to solve this senario-time formats |