<?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: When a value is missing finding the non missing value within = - 3 months from a date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559057#M156077</link>
    <description>&lt;P&gt;why don't we retain&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input id weight height vsdt:date10.;
format vsdt yymmdd10.;
datalines;
001 65 160 09MAR2017
001 65 . 06JUN2017
001 65 160 18JUL2017
002 55 158 13MAY2014
002 58 . 14SEP2014
002 58 158 15SEP2015
003 70 180 06AUG2017
003 70.5 . 01MAR2018
003 71 . 01FEB2019
;
run;

proc sort data=have;
by id vsdt;
run;

data want;
set have;
by id vsdt;
retain height_;
if first.id then height_=.;
if height ne . then height_=height;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 May 2019 16:34:08 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2019-05-15T16:34:08Z</dc:date>
    <item>
      <title>When a value is missing finding the non missing value within = - 3 months from a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559024#M156065</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this data set of weight and height measurements. Sometimes either the height&amp;nbsp; or the weight is missing.&lt;/P&gt;
&lt;P&gt;when on one the measurement is missing I want to pick the&amp;nbsp; non missing measurement&amp;nbsp; the closest date and that is in a 3 months window before or after the measurement date.&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines missover&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&amp;nbsp;id weight height vsdt&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;
&lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt;&amp;nbsp;vsdt&amp;nbsp;yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;001 65&amp;nbsp; 160&amp;nbsp; &amp;nbsp;09MAR2017&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;
001 65&amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp;06JUN2017&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="monospace"&gt;001 65&amp;nbsp; 160&amp;nbsp; &amp;nbsp;18JUL2017&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;002&amp;nbsp; 55&amp;nbsp; &amp;nbsp; &amp;nbsp;158&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13MAY2014&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;002&amp;nbsp; 58&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14SEP2014&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;002 58&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;158&amp;nbsp; &amp;nbsp; &amp;nbsp; 15SEP2015&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;003 70&amp;nbsp; &amp;nbsp; &amp;nbsp; 180&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;06AUG2017&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;003 70.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01MAR2018&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;003 71&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01FEB2019&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 15:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559024#M156065</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2019-05-15T15:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: When a value is missing finding the non missing value within = - 3 months from a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559057#M156077</link>
      <description>&lt;P&gt;why don't we retain&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input id weight height vsdt:date10.;
format vsdt yymmdd10.;
datalines;
001 65 160 09MAR2017
001 65 . 06JUN2017
001 65 160 18JUL2017
002 55 158 13MAY2014
002 58 . 14SEP2014
002 58 158 15SEP2015
003 70 180 06AUG2017
003 70.5 . 01MAR2018
003 71 . 01FEB2019
;
run;

proc sort data=have;
by id vsdt;
run;

data want;
set have;
by id vsdt;
retain height_;
if first.id then height_=.;
if height ne . then height_=height;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 May 2019 16:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559057#M156077</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-05-15T16:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: When a value is missing finding the non missing value within = - 3 months from a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559060#M156079</link>
      <description>&lt;P&gt;The retain would not work because we want the closest measurement within a 3 week window so for this patient;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;001 65 160 09MAR2017
001 65 . 06JUN2017
001 65 160 18JUL2017&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;for the record where height is missing (06JUN2017) we would want to pick the measurement on 18JUL2017 and not the one from 09MAR2017 because the 18JUL2017 is closer to 06JUNE2017 than 09MAR2017&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559060#M156079</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2019-05-15T16:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: When a value is missing finding the non missing value within = - 3 months from a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559310#M156166</link>
      <description>&lt;P&gt;Try this one :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input id weight height vsdt:date10.;
format vsdt yymmdd10.;
datalines;
001 65 160 09MAR2017
001 65 . 06JUN2017
001 65 160 18JUL2017
002 55 158 13MAY2014
002 58 . 14SEP2014
002 58 158 15SEP2015
003 70 180 06AUG2017
003 70.5 . 01MAR2018
003 71 . 01FEB2019
;
run;

proc sql;
select *,case when missing(height) then 
(select min(height) from have where id=a.id and 
vsdt between intnx('month',a.vsdt,-3,'s') and intnx('month',a.vsdt,3,'s') and
height is not missing
having abs(a.vsdt-vsdt) =  min(abs(a.vsdt-vsdt))
 )
 else height end as new_height
 from have as a;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 May 2019 14:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-a-value-is-missing-finding-the-non-missing-value-within-3/m-p/559310#M156166</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-05-16T14:34:49Z</dc:date>
    </item>
  </channel>
</rss>

