<?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: Find changes between records and create an indicator for it in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/454686#M114917</link>
    <description>&lt;P&gt;I'm sorry for not being clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There has to be a 20-day restriction between records, not on the same line. So, I want to know the number of days between the last end date and the next start date. This number has to be smaller than 20.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, if you look at my example dataset. The number of days between 30-11-2017 and 01-12-2017 is 0 (for 1392358). Therefore the change from A to B should get a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For 1847204, there are 32 days between 31-12-2017 and 02-02-2018. Therefore, the indicator should be 0 for this change.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Apr 2018 10:05:45 GMT</pubDate>
    <dc:creator>Robs234</dc:creator>
    <dc:date>2018-04-17T10:05:45Z</dc:date>
    <item>
      <title>Find changes between records and create an indicator for it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453979#M114753</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I'm quite new to SAS I'm still learning some basic steps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;contract_nr start_date end_date product_code&lt;/P&gt;&lt;P&gt;1392358 01-02-2017 31-07-2017 A&lt;BR /&gt;1392358 01-08-2017 30-11-2017 A&lt;BR /&gt;1392358 01-12-2017 28-02-2018 B&lt;BR /&gt;1392358 01-03-2018 30-04-2018 B&lt;/P&gt;&lt;P&gt;1847204 08-12-2017 31-12-2017 A&lt;/P&gt;&lt;P&gt;1847204 02-02-2018 31-03-2018 B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I tried to make a example SAS code, but failed)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to find out when a product code has changed, but only if there are less than, say, 20 days between the start and end date. So, my want dataset looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;contract_nr start_date end_date product_code&amp;nbsp;indicator&lt;/P&gt;&lt;P&gt;1392358 01-02-2017 31-07-2017 A 0&lt;BR /&gt;1392358 01-08-2017 30-11-2017 A 0&lt;BR /&gt;1392358 01-12-2017 28-02-2018 B 1&lt;BR /&gt;1392358 01-03-2018 30-04-2018 B 1&lt;/P&gt;&lt;P&gt;1847204 08-12-2017 31-12-2017 A 0&lt;/P&gt;&lt;P&gt;1847204 02-02-2018 31-03-2018 B 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way, the product code can only change from A to B.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I prefer not to use loops, but I do think we can get around them. I hope someone can help me!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 16:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453979#M114753</guid>
      <dc:creator>Robs234</dc:creator>
      <dc:date>2018-04-13T16:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Find changes between records and create an indicator for it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453981#M114754</link>
      <description>&lt;P&gt;You wrote &lt;STRONG&gt;&lt;EM&gt;"20 days between the start and end date. So, my want dataset looks like this:"&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Can you mark this in the output to help me understand better?&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 17:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453981#M114754</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-13T17:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Find changes between records and create an indicator for it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453982#M114755</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract_nr $ start_date :ddmmyy10. end_date :ddmmyy10.  product_code $;
cards;
1392358 01-02-2017 31-07-2017 A
1392358 01-08-2017 30-11-2017 A
1392358 01-12-2017 28-02-2018 B
1392358 01-03-2018 30-04-2018 B
1847204 08-12-2017 31-12-2017 A
1847204 02-02-2018 31-03-2018 B
;
run;

data want;
set have;
if start_date - lag(end_date) &amp;gt; 20 and product_code ne lag(product_code) and contract_nr = lag(contract_nr) then indicator = 1;
else indicator = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 17:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453982#M114755</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-13T17:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find changes between records and create an indicator for it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453983#M114756</link>
      <description>&lt;P&gt;It seems like, on the one hand, you are comparing a record to the record immediately above it, but then you also have this 20 day restriction which is comparing two values on the same line (and not the record above it). It's not clear to me how these two restrictions work together. If I am understanding this properly (and I probably am not understanding it properly), the 20 day restriction would mean that the indicator variable would result in zeros for every row on the table.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 17:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/453983#M114756</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-13T17:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find changes between records and create an indicator for it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/454014#M114760</link>
      <description>&lt;P&gt;Assuming i understand what you want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract_nr $ start_date :ddmmyy10. end_date :ddmmyy10.  product_code $;
format start_date end_date  ddmmyy10.;
cards;
1392358 01-02-2017 31-07-2017 A
1392358 01-08-2017 30-11-2017 A
1392358 01-12-2017 28-02-2018 B
1392358 01-03-2018 30-04-2018 B
1847204 08-12-2017 31-12-2017 A
1847204 02-02-2018 31-03-2018 B
;
run;
data want;
set have;
by contract_nr;
if first.contract_nr then call missing(k);
retain k;
indicator= product_code='B'  and intck('day',k,start_date)&amp;lt;20 ;
k=end_date;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 18:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/454014#M114760</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-13T18:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Find changes between records and create an indicator for it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/454686#M114917</link>
      <description>&lt;P&gt;I'm sorry for not being clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There has to be a 20-day restriction between records, not on the same line. So, I want to know the number of days between the last end date and the next start date. This number has to be smaller than 20.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, if you look at my example dataset. The number of days between 30-11-2017 and 01-12-2017 is 0 (for 1392358). Therefore the change from A to B should get a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For 1847204, there are 32 days between 31-12-2017 and 02-02-2018. Therefore, the indicator should be 0 for this change.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Apr 2018 10:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/454686#M114917</guid>
      <dc:creator>Robs234</dc:creator>
      <dc:date>2018-04-17T10:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Find changes between records and create an indicator for it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/454697#M114924</link>
      <description>&lt;P&gt;Thanks! Never thought it would be this easy&lt;/P&gt;</description>
      <pubDate>Tue, 17 Apr 2018 10:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-changes-between-records-and-create-an-indicator-for-it/m-p/454697#M114924</guid>
      <dc:creator>Robs234</dc:creator>
      <dc:date>2018-04-17T10:54:49Z</dc:date>
    </item>
  </channel>
</rss>

