<?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: If a certain condition is met 2 time points before the time point of treatment beginning. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859409#M339548</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; thank you so much, your code worked perfectly. It was the third case you gave that exactly fit with what I was trying to do. Thanks again!&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2023 16:58:36 GMT</pubDate>
    <dc:creator>hr667</dc:creator>
    <dc:date>2023-02-17T16:58:36Z</dc:date>
    <item>
      <title>If a certain condition is met 2 time points before the time point of treatment beginning.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859272#M339501</link>
      <description>&lt;P&gt;Looking to see if a certain condition is met two time points before the time point that treatment is started. If the condition is not meet two time points before treatment began, the participant will be excluded from the dataset. The variable "date" shows the time point that treatment is begun (date = 8 means the participant began treatment at the 8th time point [t8]). t1-t12 show whether some criterion is met (0=not met, 1=met) at each time point. I've included an example of what my data looks like below, but my dataset has over 200 time points instead of 12 and thousands of records. So I'm looking for an efficient way of doing this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data example;
input ID date t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12;
cards;
1	8	0	0	0	1	1	1	1	1	1	1	1	1
2	6	1	1	1	1	1	1	1	1	1	1	1	1
3	7	0	0	0	0	0	0	0	0	0	1	1	1
4	5	0	0	0	0	0	1	1	1	1	1	1	1
5	9	0	1	1	1	1	1	1	1	1	1	1	1
6	5	0	0	0	0	1	1	1	1	1	1	1	1
7	10	1	1	1	1	1	1	1	1	1	1	1	1
8	3	0	0	0	0	0	0	1	1	1	1	1	1
9	7	0	0	1	1	1	1	1	1	1	1	1	1
10	8	0	0	1	1	1	1	1	1	1	1	1	1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 21:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859272#M339501</guid>
      <dc:creator>hr667</dc:creator>
      <dc:date>2023-02-16T21:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: If a certain condition is met 2 time points before the time point of treatment beginning.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859275#M339502</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439640"&gt;@hr667&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can count the 1s in the substring consisting of the first &lt;FONT face="courier new,courier"&gt;date-1&lt;/FONT&gt; characters of the concatenation of variables t1, t2, ... and then select those observations where this count is at least 2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set example;
if countc(substrn(cat(of t:),1,date-1),'1')&amp;gt;1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If needed, add a WHERE condition to restrict processing to observations with non-missing dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Edit:&lt;/STRONG&gt; The above suggestion assumes that the criterion is: "The condition is met at least&amp;nbsp;&lt;EM&gt;twice&lt;/EM&gt; before treatment start."&lt;/P&gt;
&lt;P&gt;If, instead, it is "The condition is met at time point t(x-2), where t(x) is the time point of&amp;nbsp;treatment start" or&amp;nbsp;"The condition is met at time points t(x-2) &lt;EM&gt;and&lt;/EM&gt; t(x-1), where t(x) is the time point of&amp;nbsp;treatment start", then use the first or second suggestion below, respectively:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
set example;
array t[*] t:;
if date&amp;gt;2 &amp;amp; t[date-2];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want3;
set example;
array t[*] t:;
if date&amp;gt;2 &amp;amp; t[date-2] &amp;amp; t[date-1];
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 22:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859275#M339502</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-16T22:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: If a certain condition is met 2 time points before the time point of treatment beginning.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859279#M339504</link>
      <description>&lt;P&gt;Here is code to determine where the first occurrence of a value of 1 is in the sequence t1-t12. Once you know that, one more command lets you decide where whether it was two time points before the beginning of treatment, and I leave that to you as a homework assignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set example;
    first1=whichn(1,of t1-t12);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 22:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859279#M339504</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-16T22:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: If a certain condition is met 2 time points before the time point of treatment beginning.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859409#M339548</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; thank you so much, your code worked perfectly. It was the third case you gave that exactly fit with what I was trying to do. Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 16:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-a-certain-condition-is-met-2-time-points-before-the-time/m-p/859409#M339548</guid>
      <dc:creator>hr667</dc:creator>
      <dc:date>2023-02-17T16:58:36Z</dc:date>
    </item>
  </channel>
</rss>

