<?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: how to compare values back in time to identify the sequence of change in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648789#M194419</link>
    <description>You're welcome &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/257901"&gt;@havmaage&lt;/a&gt; !</description>
    <pubDate>Tue, 19 May 2020 09:39:05 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-05-19T09:39:05Z</dc:date>
    <item>
      <title>how to compare values back in time to identify the sequence of change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648782#M194411</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a datastep thats compares values some dates back in time&amp;nbsp;&lt;/P&gt;&lt;P&gt;what i am looking for is to identify which name where the amount changes every day and which only change every 5 or 7 days&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my data are like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;name , date, amount&amp;nbsp;&lt;/P&gt;&lt;P&gt;ann, 2020-05-11, 1200&lt;/P&gt;&lt;P&gt;ann, 2020-05-12, 1200&amp;nbsp;&lt;/P&gt;&lt;P&gt;ann, 2020-05-13, 1300&lt;/P&gt;&lt;P&gt;pete, 2020-05-11, 1200&lt;/P&gt;&lt;P&gt;pete, 2020-05-12, 1200&lt;/P&gt;&lt;P&gt;pete, 2020-05-13, 1200&lt;/P&gt;&lt;P&gt;simon, 2020-05-11, 200&lt;/P&gt;&lt;P&gt;simon, 2020-05-12, 1200&lt;/P&gt;&lt;P&gt;simon, 2020-05-13, 1200&lt;/P&gt;&lt;P&gt;Hope someone an help&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 08:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648782#M194411</guid>
      <dc:creator>havmaage</dc:creator>
      <dc:date>2020-05-19T08:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare values back in time to identify the sequence of change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648783#M194412</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/257901"&gt;@havmaage&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You datalines don't contain such cases...&lt;/P&gt;
&lt;P&gt;Assuming we have the following ones:&lt;/P&gt;
&lt;P&gt;- Ann has &lt;SPAN style="font-family: inherit;"&gt;changes in amount every days.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;- Simon has changes in amount&amp;nbsp;&lt;/SPAN&gt;every 5 or 7 days&amp;nbsp;&amp;lt;=&amp;gt; has no change in amount for at least 4 consecutive days.&lt;/P&gt;
&lt;DIV&gt;Is that correct?&lt;/DIV&gt;
&lt;DIV&gt;Do we assume there is always one record per day for each name?&lt;/DIV&gt;
&lt;DIV&gt;Thank you for the clarifications.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;If it is correct, you can try this:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm=",";
	input name $ date:YYMMDD10. amount;
	format date YYMMDD10.;
	datalines;
ann, 2020-05-11, 1000
ann, 2020-05-12, 1200 
ann, 2020-05-13, 1300
pete, 2020-05-11, 1200
pete, 2020-05-12, 1200
pete, 2020-05-13, 1200
simon, 2020-05-11, 200
simon, 2020-05-12, 1200
simon, 2020-05-13, 1200
simon, 2020-05-14, 1200
simon, 2020-05-15, 1200
simon, 2020-05-16, 200
simon, 2020-05-17, 400
simon, 2020-05-18, 1200
	;
run;

/* Count consecutive amounts */

data have2;
	set have;
	by name date amount;
	_lag = lag(amount);
	if first.name then consec = 0;
	if amount ne _lag then consec+1;
	drop _lag;
run;

proc freq data=have2 noprint;
	table name*consec / out=have_freq (drop=consec percent);
run;

/*** Names where the amount changes
 	 every day
	 (Assuming there is one record per day for each name) */

proc sql;
	select name
	from have2
	group by name
	having count(distinct amount) = count(distinct date);
quit;

/*** Names where the amount
	 changes every 5 or 7 days 
	 &amp;lt;=&amp;gt; does not change for at least 4 days
	 (Assuming there is one record per day for each name) */

proc sql;
	select name
	from have_freq
	group by name
	having max(count) &amp;gt;=4;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 19 May 2020 08:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648783#M194412</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-19T08:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare values back in time to identify the sequence of change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648784#M194413</link>
      <description>Yes thats correct, sorry for my bad example&lt;BR /&gt;</description>
      <pubDate>Tue, 19 May 2020 09:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648784#M194413</guid>
      <dc:creator>havmaage</dc:creator>
      <dc:date>2020-05-19T09:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare values back in time to identify the sequence of change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648785#M194414</link>
      <description>&lt;P&gt;OK no worries&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Let me know if the code above does meet your needs.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 09:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648785#M194414</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-19T09:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare values back in time to identify the sequence of change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648787#M194417</link>
      <description>Thank you so much this is perfect</description>
      <pubDate>Tue, 19 May 2020 09:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648787#M194417</guid>
      <dc:creator>havmaage</dc:creator>
      <dc:date>2020-05-19T09:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare values back in time to identify the sequence of change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648789#M194419</link>
      <description>You're welcome &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/257901"&gt;@havmaage&lt;/a&gt; !</description>
      <pubDate>Tue, 19 May 2020 09:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-values-back-in-time-to-identify-the-sequence-of/m-p/648789#M194419</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-19T09:39:05Z</dc:date>
    </item>
  </channel>
</rss>

