<?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: Last period enter fault and stayed faulty since then in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908464#M358490</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by customer_id;
retain calc;
if first.customer_id or status_fault = 0 then calc = 0;
if calc = 0 and status_fault = 1 then calc = period;
if last.customer_id;
keep customer_id calc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
    <pubDate>Sat, 16 Dec 2023 06:53:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-12-16T06:53:47Z</dc:date>
    <item>
      <title>Last period enter fault and stayed faulty since then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908462#M358484</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with information about each customer if he was in fault in each period (period 1 till 10).&lt;/P&gt;
&lt;P&gt;value 0 means no fault&lt;/P&gt;
&lt;P&gt;value 1 means fault.&lt;/P&gt;
&lt;P&gt;My target- For each customer to calculate last period he/she enter to fault and stayed in fault.&lt;/P&gt;
&lt;P&gt;For customer 111- He was never in fault&amp;nbsp; so value&amp;nbsp; should be null (calc_Last_Period_Enter_Fault=.)&lt;/P&gt;
&lt;P&gt;For customer 222-He was always in fault (since period 1) so value should be 1 (calc_Last_Period_Enter_Fault=1)&lt;/P&gt;
&lt;P&gt;For customer 333-He entered firstly int fault in period 7 and stayed faulty&amp;nbsp; so value should be 7(calc_Last_Period_Enter_Fault=7)&lt;/P&gt;
&lt;P&gt;For customer 444-He entered to fault a few times but in last period he is not faulty so value should be null (calc_Last_Period_Enter_Fault=.)&lt;/P&gt;
&lt;P&gt;For customer 555-Last period he entered fault is period 8 and since then he is faulty so value should be 8&amp;nbsp;(calc_Last_Period_Enter_Fault=8)&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;U&gt;What is the way to calculate it&amp;nbsp; via SAS code please?&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Have;
Input Customer_ID  period status_Fault;
cards;
111 1 0
111 2 0
111 3 0
111 4 0
111 5 0
111 6 0
111 7 0
111 8 0
111 9 0
111 10 0
222 1 1
222 2 1
222 3 1
222 4 1
222 5 1
222 6 1
222 7 1
222 8 1
222 9 1
222 10 1
333 1 0
333 2 0
333 3 0
333 4 0
333 5 0
333 6 0
333 7 1
333 8 1
333 9 1
333 10 1
444 1 0
444 2 0
444 3 1
444 4 1
444 5 1
444 6 0
444 7 0
444 8 1
444 9 1
444 10 0
555 1 0
555 2 0
555 3 1
555 4 1
555 5 0
555 6 0
555 7 0
555 8 1
555 9 1
555 10 1
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;s&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2023 06:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908462#M358484</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-12-16T06:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Last period enter fault and stayed faulty since then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908464#M358490</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by customer_id;
retain calc;
if first.customer_id or status_fault = 0 then calc = 0;
if calc = 0 and status_fault = 1 then calc = period;
if last.customer_id;
keep customer_id calc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2023 06:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908464#M358490</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-16T06:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Last period enter fault and stayed faulty since then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908465#M358491</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;How would you change the code if the request is to find last period enter fault without condition of faulty today?&lt;/P&gt;
&lt;P&gt;In such condition customer 444 will get value 8&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2023 07:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908465#M358491</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-12-16T07:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Last period enter fault and stayed faulty since then</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908466#M358492</link>
      <description>&lt;P&gt;For you last question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Have;
Input Customer_ID  period status_Fault;
cards;
111 1 0
111 2 0
111 3 0
111 4 0
111 5 0
111 6 0
111 7 0
111 8 0
111 9 0
111 10 0
222 1 1
222 2 1
222 3 1
222 4 1
222 5 1
222 6 1
222 7 1
222 8 1
222 9 1
222 10 1
333 1 0
333 2 0
333 3 0
333 4 0
333 5 0
333 6 0
333 7 1
333 8 1
333 9 1
333 10 1
444 1 0
444 2 0
444 3 1
444 4 1
444 5 1
444 6 0
444 7 0
444 8 1
444 9 1
444 10 0
555 1 0
555 2 0
555 3 1
555 4 1
555 5 0
555 6 0
555 7 0
555 8 1
555 9 1
555 10 1
;
Run;

data want;
 set have;
 by Customer_ID  status_Fault notsorted;
 retain want;
 if first.Customer_ID then call missing(want);
 if first.status_Fault and status_Fault then want=period;
 if last.Customer_ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Dec 2023 09:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-period-enter-fault-and-stayed-faulty-since-then/m-p/908466#M358492</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-12-16T09:46:12Z</dc:date>
    </item>
  </channel>
</rss>

