LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 9 Jul 2007 09:33:21 -0400
Reply-To:     Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject:      Re: How to assign the 2nd obs value to the 1st obs
In-Reply-To:  <BAY109-F281F2A8CC3089BAEC8EA0FB2070@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Suhong,

The rule to generate IND_PEDIFF is not clear.

1. Do you want to ignore PR-PP grouping to get this IND_PEDIFF ?

2. Comparing the PE of 1st observation with the 2nd observation, we get 1 for contiguous and 0 for non-contiguous for first row. Similarly with 2nd and 3rd for 2nd row .... (n-1)th and n-th for (n-1)th row. For the n-th row, there will not be any comparison and how to fill for IND_PEDIFF ?

Please decide the rule.

There is no look-ahead SAS function similar to LAG(), but it is possible to find a way for that functionality.

Regards,

Muthia Kachirayan

On 7/8/07, Suhong Tong <sophidt@hotmail.com> wrote: > > Hi Howard and Muthia, > > First, Thank you for helping me on my data problem. Second, I apologize > that I provided a misleading output. Instead putting the wrong output I > created, I really should have put a result that I want. Below is what I > want: > > For the data presented below, PE=78765 - 78767, 94725 - 94728 are > sequential > numbers, thus these two sets are considered as counseling calls. I believe > DIF(PE) only take care of 94726 - 94728, > IFN( first.pr, 1....) can take care of PE=78765, but not something stuck > in > the middle(not the first.), like 94725, if I understood what you suggested > correctly. > > I am thinking if SAS has some function can do things opposite to LAG > function, meaning move 1 observation up, then my problem can be taken care > of. > > Thanks, > > Sohpia > > pr pp pe IND_PEDIFF > 26117 12644 78765 1 > 26117 12644 78766 1 > 26117 12644 78767 1 > 26117 12644 79398 0 > 26117 12644 80601 0 > 26117 12644 81343 0 > 26117 12644 81503 0 > 26117 12644 83429 0 > 32640 15436 107309 0 > 32640 15436 114404 0 > 32640 15436 163072 0 > 32640 15436 166924 0 > 32640 15436 94725 1 > 32640 15436 94726 1 > 32640 15436 94727 1 > 32640 15436 94728 1 > > > > >From: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM> > >Reply-To: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM> > >To: SAS-L@LISTSERV.UGA.EDU > >Subject: Re: How to assign the 2nd obs value to the 1st obs > >Date: Sat, 7 Jul 2007 22:56:16 -0400 > > > >On Fri, 6 Jul 2007 18:57:17 -0400, Sophia Tong <sophiDT@HOTMAIL.COM> > 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 > > > >When presenting a table like this, it helps very much to reduce the > >whitespace in order to avoid wrapping. See > > > >http://sascommunity.org/wiki/Preparing_Sample_Data_for_SAS-L > > > >Now, to the question. Try something like > > > > data result; > > set given; > > by pr pp; > > IND_PEDIFF = ifn ( first.pr, 1, dif ( pe )=1 ); > > run; > > > >Notice that the indicator can be derived in one statement, with no > >intermediate variables. The DIF function combines the roles of the LAG > >function and the subtraction operator. When compared to the value 1, the > >result is either true (1) or false (0). The IFN function overrides that > >result for the first observation in each BY group. > > _________________________________________________________________ > > http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507 >


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