<?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: Pulling data closest to a date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704830#M26197</link>
    <description>&lt;P&gt;The program works great!&amp;nbsp; Thank so much!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Dec 2020 18:30:29 GMT</pubDate>
    <dc:creator>hanahch</dc:creator>
    <dc:date>2020-12-09T18:30:29Z</dc:date>
    <item>
      <title>Pulling data closest to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704625#M26163</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset that looks like the below:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;id&amp;nbsp;&amp;nbsp; enc_type&amp;nbsp; enc_date &amp;nbsp;&amp;nbsp; mi _date&amp;nbsp;&amp;nbsp;&amp;nbsp; daysdiff bp_sys bp_dias&amp;nbsp; ht&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wt&amp;nbsp;&amp;nbsp; bmi&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;3669 CL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6/8/2011 &amp;nbsp;&amp;nbsp; 6/8/2011&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 126&amp;nbsp;&amp;nbsp;&amp;nbsp; 60&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3669 CL &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 6/15/2011 &amp;nbsp; 6/8/2011&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3669 PR &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 6/17/2011 &amp;nbsp; 6/8/2011&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 136&amp;nbsp;&amp;nbsp;&amp;nbsp; 58&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3669 PR &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 6/23/2011 &amp;nbsp; 6/8/2011&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 112&amp;nbsp;&amp;nbsp;&amp;nbsp; 58&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 175.26&amp;nbsp; 195&amp;nbsp; 28.78 -&amp;gt; want this&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3695 IM &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 5/14/2014 &amp;nbsp; 5/14/2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125&amp;nbsp;&amp;nbsp;&amp;nbsp; 80&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3695 IM &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 5/21/2014 &amp;nbsp; 5/14/2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125&amp;nbsp;&amp;nbsp;&amp;nbsp; 70&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 160.02&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;gt; want this&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3744 PU &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1/8/2018 &amp;nbsp;&amp;nbsp; 12/14/2017&amp;nbsp;&amp;nbsp; 25&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 114&amp;nbsp;&amp;nbsp;&amp;nbsp; 60&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 165.1&amp;nbsp;&amp;nbsp; 174&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; -&amp;gt; want this&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3744 IM &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1/8/2018 &amp;nbsp;&amp;nbsp; 12/14/2017&amp;nbsp;&amp;nbsp; 25&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;572 PU &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6/8/2011 &amp;nbsp;&amp;nbsp; 6/8/2011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&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; 86&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 195&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 208&amp;nbsp;&amp;nbsp; 32.7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;572 CL &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4/25/2013 &amp;nbsp; 3/26/2013&amp;nbsp;&amp;nbsp;&amp;nbsp; 30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 124&amp;nbsp;&amp;nbsp;&amp;nbsp; 86&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 195&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 207&amp;nbsp;&amp;nbsp; 31.4 -&amp;gt; want this&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;574 PR &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4/3/2013 &amp;nbsp;&amp;nbsp; 6/9/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 63&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 140&amp;nbsp;&amp;nbsp;&amp;nbsp; 88&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 172.72&amp;nbsp; 224.5 34.1 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;575 PR &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4/8/2013 &amp;nbsp;&amp;nbsp; 3/26/2013&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 158&amp;nbsp;&amp;nbsp;&amp;nbsp; 80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 213&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 32.3 -&amp;gt; want this&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to pull the most complete data on BP, Wt, Ht, and BMI from encounter date that is closest within +/30 from MI_date.&amp;nbsp; Daysdiff column is the duration in days between the two dates.&amp;nbsp; If an encounter closest to MI_date has incomplete data then it needs to search for the next record till a record with complete data is found. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is greatly appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 05:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704625#M26163</guid>
      <dc:creator>hanahch</dc:creator>
      <dc:date>2020-12-09T05:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling data closest to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704635#M26164</link>
      <description>&lt;P&gt;Please post the data in usable form, have look at &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_blank" rel="nofollow noopener noreferrer noopener noreferrer"&gt;How to convert datasets to data steps&lt;/A&gt; if you don't know how to post data. Are "encounters" identified by "id" alone?&lt;/P&gt;
&lt;P&gt;Since you already have the "daysdiff", you could create another variable "non_missing_values", the function &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0h1d8gxwr1ml7n1qdt35v3i6u7r.htm" target="_self"&gt;N&lt;/A&gt; can help to fill it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 06:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704635#M26164</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-09T06:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling data closest to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704637#M26165</link>
      <description>&lt;P&gt;I don't know how your desired result looks like, so I assume you want as many observations as in your input data with the desired ht, wt, bmi for each obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id enc_type $ (enc_date mi_date)(:mmddyy10.) daysdiff 30-32 bp_sys 33-35 bp_dias 37-38 ht 40-45 wt 47-52 bmi 54-58;
format enc_date mi_date mmddyy10.;
datalines;
3669 CL 6/8/2011  6/8/2011   0  126 60                     
3669 CL 6/15/2011 6/8/2011   7                             
3669 PR 6/17/2011 6/8/2011   9  136 58                     
3669 PR 6/23/2011 6/8/2011   15 112 58 175.26 195    28.78 
3695 IM 5/14/2014 5/14/2014  0  125 80                     
3695 IM 5/21/2014 5/14/2014  7  125 70        160.02       
3744 PU 1/8/2018  12/14/2017 25 114 60 165.1  174          
3744 IM 1/8/2018  12/14/2017 25                            
572  PU 6/8/2011  6/8/2011   0      86 195    208    32.7  
572  CL 4/25/2013 3/26/2013  30 124 86 195    207    31.4  
574  PR 4/3/2013  6/9/2013   63 140 88 172.72 224.5  34.1  
575  PR 4/8/2013  3/26/2013  13 158 80 213           32.3  
;

data want;
   do _N_ = 1 by 1 until (last.id);
      set have;
      by id notsorted;

      if abs(enc_date-mi_date) &amp;lt;= 30 then do;
         if n(ht, wt, bmi) &amp;gt; n then do;
            n    = n(ht, wt, bmi);
            _ht  = ht;
            _wt  = wt;
            _bmi = bmi;
         end;
      end;
   end;

   ht  = _ht;
   wt  = _wt;
   bmi = _bmi;

   do _N_ = 1 to _N_;
      set have;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Dec 2020 06:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704637#M26165</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-09T06:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling data closest to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704830#M26197</link>
      <description>&lt;P&gt;The program works great!&amp;nbsp; Thank so much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 18:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704830#M26197</guid>
      <dc:creator>hanahch</dc:creator>
      <dc:date>2020-12-09T18:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling data closest to a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704920#M26213</link>
      <description>&lt;P&gt;Sorry one more thing - How would you change in the program so that it outputs only the encounters that have the most data of ht, wt, and BMI?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 04:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pulling-data-closest-to-a-date/m-p/704920#M26213</guid>
      <dc:creator>hanahch</dc:creator>
      <dc:date>2020-12-10T04:06:13Z</dc:date>
    </item>
  </channel>
</rss>

