<?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: Nested do loops to compare two sets of variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326251#M62309</link>
    <description>That's a very good point - thanks!</description>
    <pubDate>Fri, 20 Jan 2017 13:20:52 GMT</pubDate>
    <dc:creator>mewsmit</dc:creator>
    <dc:date>2017-01-20T13:20:52Z</dc:date>
    <item>
      <title>Nested do loops to compare two sets of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326081#M62285</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I have a dataset where each row is a different person and each column is the date that they visited the study site.&lt;/P&gt;&lt;P&gt;I have list of variables: Pdate1-Pdate1360 and Qdate1-Qdate705. I want to create a flag variable called Flagvar that indicates whether any of the Q dates fell within 30 days of any of the Pdates, but I’m new to arrays and not sure where I’m going wrong. Since I already have over 2000 columns I don't want to create a cartesian product. Here is my code:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array Pdate{&lt;STRONG&gt;1360&lt;/STRONG&gt;} Pdate1-Pdate1360;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array Qdate{&lt;STRONG&gt;705&lt;/STRONG&gt;} Qdate1-Qdate705;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do k=&lt;STRONG&gt;1&lt;/STRONG&gt; to &lt;STRONG&gt;1360&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=&lt;STRONG&gt;1&lt;/STRONG&gt; to &lt;STRONG&gt;705&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if intck('day', Pdate{k}, Qdate{j}) le &lt;STRONG&gt;30&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then Flagvar=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else Flagvar=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suggestions, please?&lt;/P&gt;&lt;P&gt;Thanks in advance! I'm using SAS 9.4.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 18:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326081#M62285</guid>
      <dc:creator>mewsmit</dc:creator>
      <dc:date>2017-01-19T18:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Nested do loops to compare two sets of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326085#M62286</link>
      <description>&lt;P&gt;Remove the Else condition from your loop. The Else resets the flag as soon as you check the next field.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want to add a LEAVE so you leave the loop when the flag is set to speed this up. Or a while condition to the loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yoir logic and code appears fine otherwise &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 19:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326085#M62286</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-19T19:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Nested do loops to compare two sets of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326105#M62289</link>
      <description>&lt;P&gt;Another issue you may need to address ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even with ELSE removed, this code gives you the wrong answer.&amp;nbsp; It properly handles PDates that come before QDates, but not the other way around.&amp;nbsp; For those cases, INTCK will give you a negative number, which is always less than 30.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When measuring days, INTCK isn't really needed.&amp;nbsp; You can just subtract one from the other.&amp;nbsp; This might be a better calculation to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;abs(Pdate{k} - Qdate{k})&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even then, be wary of missing values which will also be less than 30.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 20:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326105#M62289</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-19T20:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nested do loops to compare two sets of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326251#M62309</link>
      <description>That's a very good point - thanks!</description>
      <pubDate>Fri, 20 Jan 2017 13:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-do-loops-to-compare-two-sets-of-variables/m-p/326251#M62309</guid>
      <dc:creator>mewsmit</dc:creator>
      <dc:date>2017-01-20T13:20:52Z</dc:date>
    </item>
  </channel>
</rss>

