<?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: Data step-List Customers touch failure and belong to our pop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942568#M369598</link>
    <description>&lt;P&gt;Your logic MIGHT work if the values are sorted so that POP7 is set before all of the places where TOUCH_FAILURE is created.&amp;nbsp; But it would be much easier to just wait until you get to end of the observations for this customer.&amp;nbsp; So after the END of the DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input CustID ddate :date9.  pop Ind_Fail;
  format ddate date9.;
cards;
1 01APR2022 7 0
1 01MAY2022 7 0
1 01JUN2022 7 0
1 01JUL2022 7 0
1 01AUG2022 7 0
1 01SEP2022 7 0
1 01OCT2022 7 0
1 01NOV2022 7 0
2 01APR2022 7 0
2 01MAY2022 7 0
2 01JUN2022 7 1
2 01JUL2022 7 0
2 01AUG2022 7 0
2 01SEP2022 7 0
2 01OCT2022 7 0
2 01NOV2022 7 1
3 01APR2022 7 0
3 01MAY2022 7 0
3 01JUN2022 7 1
3 01JUL2022 7 1
3 01AUG2022 7 1
3 01SEP2022 7 1
3 01OCT2022 7 0
3 01NOV2022 7 0
4 01APR2022 8 0
4 01MAY2022 8 0
4 01JUN2022 8 1
4 01JUL2022 8 0
4 01AUG2022 8 0
4 01SEP2022 8 0
4 01OCT2022 8 0
4 01NOV2022 8 0
5 01APR2022 7 0
5 01MAY2022 7 0
5 01JUN2022 7 1
5 01JUL2022 7 0
5 01AUG2022 7 0
5 01SEP2022 7 0
5 01OCT2022 7 0
5 01NOV2022 8 0
;
data want2;
  do until(last.CustID);
    set have;
    by CustID;
    if (ddate='01NOV2022'd and pop=7) then POP7=1;
    if ddate in ('01OCT2022'd,'01SEP2022'd ,'01AUG2022'd,'01JUL2022'd,'01JUN2022'd)
       and Ind_Fail=1 then Touch_FAILURE=1;
  end; 
  pop7 = 0 or pop7;
  touch_failure=touch_failure and pop7;
  keep custid pop7 touch_failure;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;       Cust             Touch_
Obs     ID     POP7    FAILURE

 1       1       1        0
 2       2       1        1
 3       3       1        1
 4       4       0        0
 5       5       0        0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2024 19:12:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-09-04T19:12:05Z</dc:date>
    <item>
      <title>Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942537#M369584</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to get CustomerID list that meet following criteria:&lt;/P&gt;
&lt;P&gt;1- InNov 2022 they beling to popultion 7&lt;/P&gt;
&lt;P&gt;2- Between Jun2022 and OCT2022 they touch failure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below calculate correctly variable pop7&amp;nbsp; but doesn't calculate correctly variable&amp;nbsp;&lt;CODE class=" language-sas"&gt;Touch_FAILURE.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;May anyone help please?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format ddate date9.;
input CustID ddate :date9.  pop Ind_Fail;
cards;
1 '01APR2022'd 7 0
1 '01MAY2022'd 7 0
1 '01JUN2022'd 7 0
1 '01JUL2022'd 7 0
1 '01AUG2022'd 7 0
1 '01SEP2022'd 7 0
1 '01OCT2022'd 7 0
1 '01NOV2022'd 7 0
2 '01APR2022'd 7 0
2 '01MAY2022'd 7 0
2 '01JUN2022'd 7 1
2 '01JUL2022'd 7 0
2 '01AUG2022'd 7 0
2 '01SEP2022'd 7 0
2 '01OCT2022'd 7 0
2 '01NOV2022'd 7 1
3 '01APR2022'd 7 0
3 '01MAY2022'd 7 0
3 '01JUN2022'd 7 1
3 '01JUL2022'd 7 1
3 '01AUG2022'd 7 1
3 '01SEP2022'd 7 1
3 '01OCT2022'd 7 0
3 '01NOV2022'd 7 0
4 '01APR2022'd 8 0
4 '01MAY2022'd 8 0
4 '01JUN2022'd 8 1
4 '01JUL2022'd 8 0
4 '01AUG2022'd 8 0
4 '01SEP2022'd 8 0
4 '01OCT2022'd 8 0
4 '01NOV2022'd 8 0
5 '01APR2022'd 7 0
5 '01MAY2022'd 7 0
5 '01JUN2022'd 7 1
5 '01JUL2022'd 7 0
5 '01AUG2022'd 7 0
5 '01SEP2022'd 7 0
5 '01OCT2022'd 7 0
5 '01NOV2022'd 8 0
;
Run;



data want2;
do until(last.CustID);
set have(KEEP=CustID pop  ddate Ind_Fail);
by CustID;
if (ddate='01NOV2022'd and pop=7) then POP7=1;
if ddate in ('01OCT2022'd,'01SEP2022'd ,'01AUG2022'd,'01JUL2022'd,'01JUN2022'd) and Ind_Fail=1 then Touch_FAILURE=1;
end; 
keep  CustID POP7 Touch_FAILURE;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2024 17:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942537#M369584</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T17:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942538#M369585</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;... but doesn't calculate correctly variable&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="  language-sas"&gt;Touch_FAILURE&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the correct values for TOUCH_FAILURE?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 17:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942538#M369585</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-04T17:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942546#M369589</link>
      <description>0&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;0&lt;BR /&gt;0&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Sep 2024 18:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942546#M369589</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T18:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942550#M369591</link>
      <description>&lt;P&gt;You never set either variable to zero.&amp;nbsp; &amp;nbsp;You might add this after the BY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.custid then do;
  pop7=0;
  touch_failure=0;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why do the last two customers get zeros?&lt;/P&gt;
&lt;P&gt;If it is because they are not in the POP7 group then add this statement after the DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  touch_failure=pop7 and touch_failure;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 18:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942550#M369591</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-04T18:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942556#M369594</link>
      <description>&lt;P&gt;Can you please show the full code?&lt;/P&gt;
&lt;P&gt;In my code I see result only for customer 6&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format ddate date9.;
input CustID ddate :date9.  pop Ind_Fail;
cards;
1 '01APR2022'd 7 0
1 '01MAY2022'd 7 0
1 '01JUN2022'd 7 0
1 '01JUL2022'd 7 0
1 '01AUG2022'd 7 0
1 '01SEP2022'd 7 0
1 '01OCT2022'd 7 0
1 '01NOV2022'd 7 0
2 '01APR2022'd 7 0
2 '01MAY2022'd 7 0
2 '01JUN2022'd 7 1
2 '01JUL2022'd 7 0
2 '01AUG2022'd 7 0
2 '01SEP2022'd 7 0
2 '01OCT2022'd 7 0
2 '01NOV2022'd 7 1
3 '01APR2022'd 7 0
3 '01MAY2022'd 7 0
3 '01JUN2022'd 7 1
3 '01JUL2022'd 7 1
3 '01AUG2022'd 7 1
3 '01SEP2022'd 7 1
3 '01OCT2022'd 7 0
3 '01NOV2022'd 7 0
4 '01APR2022'd 8 0
4 '01MAY2022'd 8 0
4 '01JUN2022'd 8 1
4 '01JUL2022'd 8 0
4 '01AUG2022'd 8 0
4 '01SEP2022'd 8 0
4 '01OCT2022'd 8 0
4 '01NOV2022'd 8 0
5 '01APR2022'd 7 0
5 '01MAY2022'd 7 0
5 '01JUN2022'd 7 1
5 '01JUL2022'd 7 0
5 '01AUG2022'd 7 0
5 '01SEP2022'd 7 0
5 '01OCT2022'd 7 0
5 '01NOV2022'd 8 0
6 '01APR2022'd 7 0
6 '01MAY2022'd 7 0
6 '01JUN2022'd 8 1
6 '01JUL2022'd 8 1
6 '01AUG2022'd 8 1
6 '01SEP2022'd 8 1
6 '01OCT2022'd 8 1
6 '01NOV2022'd 7 0
;
Run;

data want;
do until(last.CustID);
set have(KEEP=CustID pop  ddate Ind_Fail);
by CustID;

if first.custid then do;
  pop7=0;
  touch_failure=0;
end;

if (ddate='01NOV2022'd and pop=7) then POP7=1;
if ddate in ('01OCT2022'd,'01SEP2022'd ,'01AUG2022'd,'01JUL2022'd,'01JUN2022'd) and Ind_Fail=1 then _Touch_FAILURE_=1;
touch_failure=pop7 and _Touch_FAILURE_;
end; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 18:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942556#M369594</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T18:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942568#M369598</link>
      <description>&lt;P&gt;Your logic MIGHT work if the values are sorted so that POP7 is set before all of the places where TOUCH_FAILURE is created.&amp;nbsp; But it would be much easier to just wait until you get to end of the observations for this customer.&amp;nbsp; So after the END of the DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input CustID ddate :date9.  pop Ind_Fail;
  format ddate date9.;
cards;
1 01APR2022 7 0
1 01MAY2022 7 0
1 01JUN2022 7 0
1 01JUL2022 7 0
1 01AUG2022 7 0
1 01SEP2022 7 0
1 01OCT2022 7 0
1 01NOV2022 7 0
2 01APR2022 7 0
2 01MAY2022 7 0
2 01JUN2022 7 1
2 01JUL2022 7 0
2 01AUG2022 7 0
2 01SEP2022 7 0
2 01OCT2022 7 0
2 01NOV2022 7 1
3 01APR2022 7 0
3 01MAY2022 7 0
3 01JUN2022 7 1
3 01JUL2022 7 1
3 01AUG2022 7 1
3 01SEP2022 7 1
3 01OCT2022 7 0
3 01NOV2022 7 0
4 01APR2022 8 0
4 01MAY2022 8 0
4 01JUN2022 8 1
4 01JUL2022 8 0
4 01AUG2022 8 0
4 01SEP2022 8 0
4 01OCT2022 8 0
4 01NOV2022 8 0
5 01APR2022 7 0
5 01MAY2022 7 0
5 01JUN2022 7 1
5 01JUL2022 7 0
5 01AUG2022 7 0
5 01SEP2022 7 0
5 01OCT2022 7 0
5 01NOV2022 8 0
;
data want2;
  do until(last.CustID);
    set have;
    by CustID;
    if (ddate='01NOV2022'd and pop=7) then POP7=1;
    if ddate in ('01OCT2022'd,'01SEP2022'd ,'01AUG2022'd,'01JUL2022'd,'01JUN2022'd)
       and Ind_Fail=1 then Touch_FAILURE=1;
  end; 
  pop7 = 0 or pop7;
  touch_failure=touch_failure and pop7;
  keep custid pop7 touch_failure;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;       Cust             Touch_
Obs     ID     POP7    FAILURE

 1       1       1        0
 2       2       1        1
 3       3       1        1
 4       4       0        0
 5       5       0        0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 19:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942568#M369598</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-04T19:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942634#M369626</link>
      <description>&lt;P&gt;I think a self-merge might be slightly simpler than a SET inside a DO group:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=custid pop7 touchfail);
  merge have
        have (where=(ddate='01nov2022'd and pop=7)  in=p7)
        have (where=(('01jun2022'd&amp;lt;=ddate&amp;lt;='30oct2022'd) and ind_fail=1) in=fail);
  by custid;
  if first.custid ;
  pop7=p7;
  touchfail=fail and p7;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Sep 2024 02:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942634#M369626</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-09-05T02:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Data step-List Customers touch failure and belong to our pop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942693#M369640</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;0&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;0&lt;BR /&gt;0&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This doesn't match your description in words in the initial problem statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please from now on, when you are getting the wrong results, you need to specifically show us the right results, as we cannot tell from your words and we cannot tell from your code. I know in the past you have provided the WANT data set, we need that all the time if the issue is that your results are not what you want.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 13:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-List-Customers-touch-failure-and-belong-to-our-pop/m-p/942693#M369640</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-05T13:56:36Z</dc:date>
    </item>
  </channel>
</rss>

