<?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 Lag with calculate indicator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Lag-with-calculate-indicator/m-p/944367#M370015</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;For each customer I have 12 rows&amp;nbsp; which represent data of last 12 months.&lt;/P&gt;
&lt;P&gt;Month 1 is last month.&lt;/P&gt;
&lt;P&gt;Month 12 is the month 12 months ago.&lt;/P&gt;
&lt;P&gt;For each customer I want to calculate for each row (From row 2 till row 12) an indicator that get value 1 IF at least one of following conditions happen:&lt;/P&gt;
&lt;P&gt;condition1- If from month to next month there is increase of more than 10% and the next value ratio is higher than 0.5&lt;/P&gt;
&lt;P&gt;condition2-IF from one month to next month there is increase and previous month is lower than 1 and next month is higher than 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;month1= 0.4 , month2= 0.45&amp;nbsp; &amp;nbsp; then indicator=0 because both conditions no meet&lt;/P&gt;
&lt;P&gt;month1=0.4&amp;nbsp; &amp;nbsp; month2=0.6 then indicator=1 because condition 1 meet&lt;/P&gt;
&lt;P&gt;month1=0.98&amp;nbsp; month2=1.01&amp;nbsp; then indicator=1 because condition 2 meet&lt;/P&gt;
&lt;P&gt;month1=1.1&amp;nbsp; &amp;nbsp; &amp;nbsp; month2=1.3 then indicator=1 because condition 1 meet&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is the way to calculate the indicator please?&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;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input CustID month Ratio;
cards;
1 1 0.4
1 2 0.45
1 3 0.2
1 4 0.7
1 5 0.75
1 6 0.5
1 7 0.7
1 8 0.9
1 9 1.2
1 10 1.4
1 11 0.8
1 12 0.7
2 1 0.3
2 2 0.25
2 3 0.4
2 4 0.9
2 5 0.85
2 6 0.6
2 7 0.5
2 8 0.8
2 9 1.3
2 10 0.7
2 11 0.7
2 12 0.4
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 09:42:59 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2024-09-18T09:42:59Z</dc:date>
    <item>
      <title>Lag with calculate indicator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-with-calculate-indicator/m-p/944367#M370015</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;For each customer I have 12 rows&amp;nbsp; which represent data of last 12 months.&lt;/P&gt;
&lt;P&gt;Month 1 is last month.&lt;/P&gt;
&lt;P&gt;Month 12 is the month 12 months ago.&lt;/P&gt;
&lt;P&gt;For each customer I want to calculate for each row (From row 2 till row 12) an indicator that get value 1 IF at least one of following conditions happen:&lt;/P&gt;
&lt;P&gt;condition1- If from month to next month there is increase of more than 10% and the next value ratio is higher than 0.5&lt;/P&gt;
&lt;P&gt;condition2-IF from one month to next month there is increase and previous month is lower than 1 and next month is higher than 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;month1= 0.4 , month2= 0.45&amp;nbsp; &amp;nbsp; then indicator=0 because both conditions no meet&lt;/P&gt;
&lt;P&gt;month1=0.4&amp;nbsp; &amp;nbsp; month2=0.6 then indicator=1 because condition 1 meet&lt;/P&gt;
&lt;P&gt;month1=0.98&amp;nbsp; month2=1.01&amp;nbsp; then indicator=1 because condition 2 meet&lt;/P&gt;
&lt;P&gt;month1=1.1&amp;nbsp; &amp;nbsp; &amp;nbsp; month2=1.3 then indicator=1 because condition 1 meet&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is the way to calculate the indicator please?&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;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input CustID month Ratio;
cards;
1 1 0.4
1 2 0.45
1 3 0.2
1 4 0.7
1 5 0.75
1 6 0.5
1 7 0.7
1 8 0.9
1 9 1.2
1 10 1.4
1 11 0.8
1 12 0.7
2 1 0.3
2 2 0.25
2 3 0.4
2 4 0.9
2 5 0.85
2 6 0.6
2 7 0.5
2 8 0.8
2 9 1.3
2 10 0.7
2 11 0.7
2 12 0.4
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 09:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-with-calculate-indicator/m-p/944367#M370015</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-18T09:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Lag with calculate indicator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-with-calculate-indicator/m-p/944375#M370016</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input CustID month Ratio;
cards;
1 1 0.4
1 2 0.45
1 3 0.2
1 4 0.7
1 5 0.75
1 6 0.5
1 7 0.7
1 8 0.9
1 9 1.2
1 10 1.4
1 11 0.8
1 12 0.7
2 1 0.3
2 2 0.25
2 3 0.4
2 4 0.9
2 5 0.85
2 6 0.6
2 7 0.5
2 8 0.8
2 9 1.3
2 10 0.7
2 11 0.7
2 12 0.4
;
Run;


data want;

   merge have 
         have(firstobs = 2 rename = (Ratio = lead_r));
   by CustID;
   
   lag_r = ifn(first.CustID, ., lag(Ratio));
   if last.CustID then lead_r = .;
   
   /* Condition 1 */ 
   indicator = (Ratio &amp;gt; 1.1*lag_r and lead_r &amp;gt; .5);
  
   /* Condition 2 */ 
   indicator = max(indicator, (Ratio &amp;gt; lag_r and lag_r &amp;lt; 1 and lead_r &amp;gt; 1)); 
   
   drop lead_r lag_r;
   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 10:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-with-calculate-indicator/m-p/944375#M370016</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-09-18T10:53:11Z</dc:date>
    </item>
  </channel>
</rss>

