<?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 Using Array to compare and keep records based upon dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753015#M237268</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I've been trying, and failing, to construct an array that compares dates across a row and sets a flag on that record to keep it or not. The 1st three date columns (trandt1-trandt3) are the transposed treatment dates for a patient (this patient had 3 on 26Dec17, 22Jan19, and 07Feb20), the next date column is the treatment date itself, and the last column is the date a score was assigned. Where&amp;nbsp;&lt;EM&gt;keeper&lt;/EM&gt; is equal to '1' are the rows I want to keep, and this b/c 1) the treatment date is equal to the score date or 2) the score is &amp;gt; treatment date but not &amp;gt; the other transposed treatment dates. Make sense?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visits;&lt;BR /&gt;input id trandt1 :date9. trandt2 :date9. trandt3 :date9. visit_dt :date9. score_dt :date9. keeper;&lt;BR /&gt;format trandt1 :date9. trandt2 :date9. trandt3 :date9. visit_dt :date9. score_dt :date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 26Dec2017 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 03Jan2018 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 22Jan2019 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 07Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 13Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 22Jan2019 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 07Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 13Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 07Feb2020 07Feb2020 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 07Feb2020 13Feb2020 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jul 2021 21:29:31 GMT</pubDate>
    <dc:creator>BrianB4233</dc:creator>
    <dc:date>2021-07-08T21:29:31Z</dc:date>
    <item>
      <title>Using Array to compare and keep records based upon dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753015#M237268</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I've been trying, and failing, to construct an array that compares dates across a row and sets a flag on that record to keep it or not. The 1st three date columns (trandt1-trandt3) are the transposed treatment dates for a patient (this patient had 3 on 26Dec17, 22Jan19, and 07Feb20), the next date column is the treatment date itself, and the last column is the date a score was assigned. Where&amp;nbsp;&lt;EM&gt;keeper&lt;/EM&gt; is equal to '1' are the rows I want to keep, and this b/c 1) the treatment date is equal to the score date or 2) the score is &amp;gt; treatment date but not &amp;gt; the other transposed treatment dates. Make sense?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visits;&lt;BR /&gt;input id trandt1 :date9. trandt2 :date9. trandt3 :date9. visit_dt :date9. score_dt :date9. keeper;&lt;BR /&gt;format trandt1 :date9. trandt2 :date9. trandt3 :date9. visit_dt :date9. score_dt :date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 26Dec2017 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 03Jan2018 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 22Jan2019 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 07Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 13Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 22Jan2019 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 07Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 13Feb2020 0&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 07Feb2020 07Feb2020 1&lt;BR /&gt;1 26Dec2017 22Jan2019 07Feb2020 07Feb2020 13Feb2020 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 21:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753015#M237268</guid>
      <dc:creator>BrianB4233</dc:creator>
      <dc:date>2021-07-08T21:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using Array to compare and keep records based upon dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753017#M237269</link>
      <description>&lt;P&gt;Often, it is best not to impose a condition on how the solution should be programmed. This does not strike me as case where an ARRAY would be helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, the wording used in your explanation is somewhat vague and even pencil and paper I cannot match your keeper values. In particular, I cannot make these words align with the values of keeper in your data set: "the score is &amp;gt; treatment date but not &amp;gt; the other transposed treatment dates".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you perhaps mean "the score is &amp;gt; treatment date but not &amp;gt; maximum of the other transposed treatment dates"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or do you perhaps mean "the score is &amp;gt; treatment date but not &amp;gt; minimum of the other transposed treatment dates"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or do you perhaps mean something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is sample code that can be modified depending on what you actually mean, and which does not use arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data visits;
input id trandt1 :date9. trandt2 :date9. trandt3 :date9. visit_dt :date9. score_dt :date9.;
format trandt1 :date9. trandt2 :date9. trandt3 :date9. visit_dt :date9. score_dt :date9.;
datalines;
1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 26Dec2017 1
1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 03Jan2018 1
1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 22Jan2019 0
1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 07Feb2020 0
1 26Dec2017 22Jan2019 07Feb2020 26Dec2017 13Feb2020 0
1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 22Jan2019 1
1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 07Feb2020 0
1 26Dec2017 22Jan2019 07Feb2020 22Jan2019 13Feb2020 0
1 26Dec2017 22Jan2019 07Feb2020 07Feb2020 07Feb2020 1
1 26Dec2017 22Jan2019 07Feb2020 07Feb2020 13Feb2020 1
;
run;

data want;
    set visits;
    if (score_dt=visit_dt) or (score_dt&amp;gt;visit_dt and score_dt&amp;lt;=max(of trandt1-trandt3)) then keeper=1;
    else keeper=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 21:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753017#M237269</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-08T21:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using Array to compare and keep records based upon dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753022#M237274</link>
      <description>Thank you for your reply, and agreed, my wording is a bit vague. What I'm looking for is your 2nd condition: "the score is &amp;gt; treatment date butnot &amp;gt; minimum of the other transposed treatment dates".</description>
      <pubDate>Thu, 08 Jul 2021 22:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753022#M237274</guid>
      <dc:creator>BrianB4233</dc:creator>
      <dc:date>2021-07-08T22:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using Array to compare and keep records based upon dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753024#M237276</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271814"&gt;@BrianB4233&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your reply, and agreed, my wording is a bit vague. What I'm looking for is your 2nd condition: "the score is &amp;gt; treatment date butnot &amp;gt; minimum of the other transposed treatment dates".&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then this is a simple change to the code I provided.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 22:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Array-to-compare-and-keep-records-based-upon-dates/m-p/753024#M237276</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-08T22:06:54Z</dc:date>
    </item>
  </channel>
</rss>

