<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Group data and time difference between groups of interest in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368976#M11136</link>
    <description>&lt;P&gt;Many thanks for the replay! Awesome. What does the comma &amp;nbsp;dot&amp;nbsp;&amp;nbsp; ,.&amp;nbsp; at the end of your formaula archieve?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the names, No CL_ID and names would have to remain intact, as it would be difficult to go through 7 mio records to assess which ones would be similiar. I would only need to know, which CL_ID have different names to them - and to be more specifoc&lt;/P&gt;&lt;P&gt;Which CL_ID with the same Refer_ID and the same Refer_DT have different names to them, and if so, where and which ones are they.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So looking at the example table I have provided: CL_ID 7, has two&amp;nbsp;different Refer_ID:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Refer_ID 647594 with the names Allessandra and Victor on the same date: 4/10/2003&lt;/P&gt;&lt;P&gt;Refer_ID&amp;nbsp;1728512 with the names Allessandra and Sandra on the same date : 8/1/2005&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I would want to know that there is a discrepancy in names in Refer_ID 647594 on the same date: 4/10/2003 - and if possible I would want to know what that discrepancy is, unless i then can filter for that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would tihink a lot of grouping then data and then requesting an output based on same groups. But I am not sure how to start.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jun 2017 23:20:44 GMT</pubDate>
    <dc:creator>AnnaNZ</dc:creator>
    <dc:date>2017-06-20T23:20:44Z</dc:date>
    <item>
      <title>Group data and time difference between groups of interest</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368530#M11117</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have a case I am needed help with and I show the dataas a picture first to make my question better understandable. Data is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with repeated measurements&lt;/P&gt;&lt;P&gt;For each grouped Client_ID : CL_ID, I need the time-difference(in form of a new time variable)&amp;nbsp;from the second to the firsr, then the third to the&amp;nbsp;second then the&amp;nbsp;fourth to third&amp;nbsp;(and so on) referal Time: Refer_DT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have showcased this in excel as in the picture below: timedifference between referral 1 and 2 in CLient_ID 7 would be d5 - d4: 0 days; timedifference between referral&amp;nbsp;2 and&amp;nbsp;3 in CLient_ID 7 would be d6 - d7: 462 days;&amp;nbsp;timedifference between referral&amp;nbsp;3 and&amp;nbsp;4 in CLient_ID 7 would be d7 - d6: 0 days. that is all for them , no time difference for Client_ID 12 and 19 as they occur only once, but then the same thing for Client_ID 21&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, as can be seen in this dataset, names don't always agree with CLient_ID and I would need to knw how ofen and where this occurs: like CL_ID 21, which has the names Alessandra and Yoda. In this case Allessandra cannot be right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The way I thought about this was using First.byvariable and&amp;nbsp;Last.byvariable, would it would not resolve any of the calculation inbetween first and last.&lt;/P&gt;&lt;P&gt;Where do I start with sometihng like this?&lt;/P&gt;&lt;P&gt;Many thanks for any help and time .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG title="test.JPG" alt="test.JPG" src="https://communities.sas.com/t5/image/serverpage/image-id/9515iD3C6EFD4674635A1/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;REFER_ID&lt;/TD&gt;&lt;TD&gt;CL_ID&lt;/TD&gt;&lt;TD&gt;PUPIL_NAME&lt;/TD&gt;&lt;TD&gt;REFER_DT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1532403&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Sandra&lt;/TD&gt;&lt;TD&gt;16/10/2001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1647594&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;Allessandra&lt;/TD&gt;&lt;TD&gt;4/10/2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1647594&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;Victor&lt;/TD&gt;&lt;TD&gt;4/10/2003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1728512&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;Allessandra&lt;/TD&gt;&lt;TD&gt;8/01/2005&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1728512&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;Sandra&lt;/TD&gt;&lt;TD&gt;8/01/2005&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt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lt;TD&gt;23/09/2005&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1943047&lt;/TD&gt;&lt;TD&gt;29&lt;/TD&gt;&lt;TD&gt;Allessandra&lt;/TD&gt;&lt;TD&gt;17/01/2008&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1943047&lt;/TD&gt;&lt;TD&gt;29&lt;/TD&gt;&lt;TD&gt;Yoda&lt;/TD&gt;&lt;TD&gt;17/01/2008&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1753853&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;Allessandra&lt;/TD&gt;&lt;TD&gt;16/05/2005&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1847720&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;Allessandra&lt;/TD&gt;&lt;TD&gt;22/09/2006&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 23:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368530#M11117</guid>
      <dc:creator>AnnaNZ</dc:creator>
      <dc:date>2017-06-19T23:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Group data and time difference between groups of interest</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368533#M11118</link>
      <description>&lt;P&gt;Regarding the calculations, the following should work:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by CL_ID;
  days_between_referal=ifn(first.cl_id eq 0,refer_dt-lag(REFER_DT),.);
run;
&lt;/PRE&gt;
&lt;P&gt;However, about the name discrepancies, you'd have to specify what you want to achieve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 00:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368533#M11118</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-20T00:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Group data and time difference between groups of interest</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368970#M11134</link>
      <description>&lt;P&gt;Thank you &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711" target="_self"&gt;&lt;SPAN class="login-bold"&gt;art297&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;! That works.&lt;/P&gt;&lt;P&gt;I'll post this as SOLUTION, but wanted to replay first&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What does the lag statemenet do exactly?&lt;/P&gt;&lt;P&gt;refer_dt-lag(REFER_DT),.) How would this part translate in words?&lt;/P&gt;&lt;P&gt;Lag = &amp;nbsp;the previous record in ()REFER_DT ?&lt;/P&gt;&lt;P&gt;, .&amp;nbsp; - what dooes this stand for - eventually I want to be able to program somethying like this myself, therefore I would like to learn more about this formula &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now with the names. I would like to see a variable that tells me where for each CL_ID there is a mismatch in names&lt;/P&gt;&lt;P&gt;Then I could filter for this mismatch and find out more about why there are different values in there.&lt;/P&gt;&lt;P&gt;Many thanks, Anna&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 22:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368970#M11134</guid>
      <dc:creator>AnnaNZ</dc:creator>
      <dc:date>2017-06-20T22:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Group data and time difference between groups of interest</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368975#M11135</link>
      <description>&lt;P&gt;Yes, lag(refer_dt) gets the previous value of refer_dt. A full description of the function can be found at:&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212547.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212547.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used it with the ifn function, starting with the condition first.cl_id eq 0 so that two things would occur&lt;/P&gt;
&lt;P&gt;1. it would always execute the lag statement&lt;/P&gt;
&lt;P&gt;but&lt;/P&gt;
&lt;P&gt;2. only use it if it wasn't the first cl_id in a set of cl_ids.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for the names, are you thinking about resetting cl_id to only contain the same names?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, would you consider Sandra and&amp;nbsp;Allessandra to be the same or different persons?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 22:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368975#M11135</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-20T22:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Group data and time difference between groups of interest</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368976#M11136</link>
      <description>&lt;P&gt;Many thanks for the replay! Awesome. What does the comma &amp;nbsp;dot&amp;nbsp;&amp;nbsp; ,.&amp;nbsp; at the end of your formaula archieve?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the names, No CL_ID and names would have to remain intact, as it would be difficult to go through 7 mio records to assess which ones would be similiar. I would only need to know, which CL_ID have different names to them - and to be more specifoc&lt;/P&gt;&lt;P&gt;Which CL_ID with the same Refer_ID and the same Refer_DT have different names to them, and if so, where and which ones are they.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So looking at the example table I have provided: CL_ID 7, has two&amp;nbsp;different Refer_ID:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Refer_ID 647594 with the names Allessandra and Victor on the same date: 4/10/2003&lt;/P&gt;&lt;P&gt;Refer_ID&amp;nbsp;1728512 with the names Allessandra and Sandra on the same date : 8/1/2005&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I would want to know that there is a discrepancy in names in Refer_ID 647594 on the same date: 4/10/2003 - and if possible I would want to know what that discrepancy is, unless i then can filter for that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would tihink a lot of grouping then data and then requesting an output based on same groups. But I am not sure how to start.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 23:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368976#M11136</guid>
      <dc:creator>AnnaNZ</dc:creator>
      <dc:date>2017-06-20T23:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Group data and time difference between groups of interest</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368980#M11137</link>
      <description>&lt;P&gt;ifn and ifc are if-then-else functions. the if, then and else are separated by commas. Thus, the the ,. at the end of the call to the function is setting the value to missing if it is the first in a series of CL_IDs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like the following would be a good start for your question regarding names:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  create table test as
    select pupil_name,refer_id
      from have
        group by refer_id
          having count(*) gt 1 and
                 count(distinct pupil_name) gt 1
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 23:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/368980#M11137</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-20T23:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Group data and time difference between groups of interest</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/369688#M11153</link>
      <description>&lt;P&gt;Hi Art, Thank you so much. I tweaked the code to me needs and it works! Fantastic!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 20:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Group-data-and-time-difference-between-groups-of-interest/m-p/369688#M11153</guid>
      <dc:creator>AnnaNZ</dc:creator>
      <dc:date>2017-06-22T20:07:22Z</dc:date>
    </item>
  </channel>
</rss>

