```Date: Sat, 7 Jul 2007 11:25:28 -0400 Reply-To: Muthia Kachirayan Sender: "SAS(r) Discussion" From: Muthia Kachirayan Subject: Re: How to assign the 2nd obs value to the 1st obs Comments: To: Sophia Tong In-Reply-To: <200707062257.l66KCUYS003332@mailgw.cc.uga.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Sophia, The lag-function goes by ignoring group-boundaries(PR-PP). You can save it to say, PREV and use it in the next observation. Here is the code as I understand your problem. data have; input pr pp pe ; cards; 26117 12644 78765 26117 12644 78766 26117 12644 78767 26117 12644 79398 26117 12644 80601 26117 12644 81343 26117 12644 81503 26117 12644 83429 32640 15436 107309 32640 15436 114404 32640 15436 163072 32640 15436 166924 32640 15436 94725 32640 15436 94726 32640 15436 94727 32640 15436 94728 ; run; proc sort data = have; by pr pp; run; data want; set have; by pr pp; retain prev; if first.pp then pe_diff = 1; else do; if (pe - prev) = 1 then pe_diff = 1; else pe_diff = 0; end; prev = pe; run; proc print data = want; run; Muthia Kachirayan On 7/6/07, Sophia Tong wrote: > > Dear list, > > I am trying to determine whether a call is a real counseling call or > random > incoming call by looking at the PE numbers. If under the same PR-PP, PE > come as a sequential numbers then that set of sequential numbers consider > as > a set of counseling calls. > > What I did is let PE2=lag(PE), then PE_DIFF=PE-PE2, if PE_DIFF=1 then that > call identified as a conseling call. As you see below, the first obs with > PE_DIFF=-264, this one should be identified as a real call. Another one > where PE_DIFF=-72199, that one also should be identified as a real call. > > My question is how to assign 1s to IND_PEDIFF after SAS see the first 1s > in > PE_DIFF? > Mine way of flagging in IND_PEDIFF does not cover all the cases. Please > help. > > Thanks in advance. > > Sophia > The SAS System 08:03 > Friday, July 6, 2007 30 > > IND_ > PR PP PE PE2 PE_DIFF PEDIFF > CALLS > > 26117 12644 78765 79029 -264 1 > 1 > 26117 12644 78766 78765 1 1 > 2 > 26117 12644 78767 78766 1 1 > 3 > 26117 12644 79398 78767 631 0 > 4 > 26117 12644 80601 79398 1203 0 > 5 > 26117 12644 81343 80601 742 0 > 6 > 26117 12644 81503 81343 160 0 > 7 > 26117 12644 83429 81503 1926 0 > 8 > 32640 15436 107309 94633 12676 1 > 1 > 32640 15436 114404 107309 7095 0 > 2 > 32640 15436 163072 114404 48668 0 > 3 > 32640 15436 166924 163072 3852 0 > 4 > 32640 15436 94725 166924 -72199 0 > 5 > 32640 15436 94726 94725 1 1 > 6 > 32640 15436 94727 94726 1 1 > 7 > 32640 15436 94728 94727 1 1 > 8 > ```

Back to: Top of message | Previous page | Main SAS-L page