<?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: Array to find closest data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-to-find-closest-data/m-p/627339#M185170</link>
    <description>&lt;P&gt;Probably the data is wrong, and some of the date variables have missing values.&amp;nbsp; This statement needs to change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if abs(date[i] - GFR_date) &amp;lt; diff then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If one of the dates is missing, this generates a missing value which is certainly less than DIFF.&amp;nbsp; So the final DIFF value would be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if . &amp;lt; abs(date[i] - GFR_date) &amp;lt; diff then do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Feb 2020 21:45:12 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-02-25T21:45:12Z</dc:date>
    <item>
      <title>Array to find closest data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-find-closest-data/m-p/627301#M185144</link>
      <description>&lt;P&gt;I am trying to find the closest date (date1-date680 date9.) to GFR_date (date9.) for each person (ID).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the code below, which would work if GFR_date was a date constant (&lt;A href="https://blogs.sas.com/content/sgf/2014/11/21/sas-arrays-be-not-afraid/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2014/11/21/sas-arrays-be-not-afraid/&lt;/A&gt;) but in my case GFR_date is different for each person.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data results (keep = ID closest diff GFR_date);&lt;BR /&gt;format ID 3. date1-date680 closest date9.;&lt;BR /&gt;set egfr;&lt;BR /&gt;array date[*] date1-date680;&lt;BR /&gt;closest = date[1];&lt;BR /&gt;diff = abs(date[1] - GFR_date);&lt;BR /&gt;do i = 2 to dim(date);&lt;BR /&gt;if abs(date[i] - GFR_date) &amp;lt; diff then do;&lt;BR /&gt;closest = date[i];&lt;BR /&gt;diff = abs(date[i] - GFR_date);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 19:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-find-closest-data/m-p/627301#M185144</guid>
      <dc:creator>greveam</dc:creator>
      <dc:date>2020-02-25T19:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Array to find closest data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-find-closest-data/m-p/627315#M185155</link>
      <description>&lt;P&gt;It should work just as well. What problem did you encounter?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 20:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-find-closest-data/m-p/627315#M185155</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-02-25T20:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: Array to find closest data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-find-closest-data/m-p/627339#M185170</link>
      <description>&lt;P&gt;Probably the data is wrong, and some of the date variables have missing values.&amp;nbsp; This statement needs to change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if abs(date[i] - GFR_date) &amp;lt; diff then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If one of the dates is missing, this generates a missing value which is certainly less than DIFF.&amp;nbsp; So the final DIFF value would be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if . &amp;lt; abs(date[i] - GFR_date) &amp;lt; diff then do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Feb 2020 21:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-find-closest-data/m-p/627339#M185170</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-25T21:45:12Z</dc:date>
    </item>
  </channel>
</rss>

