<?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: Fill missing values with other values depending on frequency in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/537329#M16575</link>
    <description>Similar but different:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;prior_age = lag(age);&lt;BR /&gt;N_days = dif(visit_date) + 365/2;&lt;BR /&gt;if first.id=0 and age=. then age =&lt;BR /&gt;prior_age + int(n_days / 365) ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Also, consider using a denominator of 365.25 instead of 365.</description>
    <pubDate>Thu, 21 Feb 2019 07:21:30 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-21T07:21:30Z</dc:date>
    <item>
      <title>Fill missing values with other values depending on frequency</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536882#M16559</link>
      <description>&lt;P&gt;Hi Everyone!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my data setup&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;visit&amp;nbsp; &amp;nbsp;visit_date&amp;nbsp; &amp;nbsp;age&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;470&amp;nbsp; &amp;nbsp; &amp;nbsp; 2247&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;480&amp;nbsp; &amp;nbsp; &amp;nbsp; 2500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&amp;nbsp; &amp;nbsp; &amp;nbsp; 2800&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 57&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;510&amp;nbsp; &amp;nbsp; &amp;nbsp; 2984&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 58&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;510&amp;nbsp; &amp;nbsp; &amp;nbsp; 3050&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;520&amp;nbsp; &amp;nbsp; &amp;nbsp; 3175&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;470&amp;nbsp; &amp;nbsp; &amp;nbsp; 2278&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 42&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;480&amp;nbsp; &amp;nbsp; &amp;nbsp; 2585&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 43&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a long dataset with multiple visits per person. I am trying to fill in the missing ages. I'd like to do this by taking the time between the visit dates added to the age at the prior visit to find the age for the next visit. I would like to "assume" that each person is at the halfway mark of their age (ie age=55 is actually age=55.5, but my dataset only has whole numbers).&amp;nbsp; Ie for ID #1 I'd like it to fill in the blank with 2500-2247= 253&amp;nbsp; + (365/2 to account for the mid year assumption). So then it would be 55.5+ (253/365)= 56.19 and then just round down to the closest whole number so the blank would be filled with 56.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to do it this way to account for any participants where there may be a large gap between visits so I don't just assume they are 1 year older at the subsequent visit.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help with this - I haven't been able to figure out any decent approach to it so any guidance is appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 19:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536882#M16559</guid>
      <dc:creator>bgosiker</dc:creator>
      <dc:date>2019-02-19T19:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with other values depending on frequency</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536885#M16560</link>
      <description>&lt;P&gt;Should we extend the logic?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if two AGE values in a row are missing, should both be filled in based on the most recent nonmissing value?&amp;nbsp; If the very first AGE is missing for an ID, should we work backwards from the next available AGE value?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 19:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536885#M16560</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-19T19:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with other values depending on frequency</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536888#M16561</link>
      <description>&lt;P&gt;In this case, I have the dataset cut down to two visits for isolating the age at a specific time (the second visit) and no one has both ages missing, so basing it off of carrying forward + the difference between the visit times should be sufficient for me!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 19:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536888#M16561</guid>
      <dc:creator>bgosiker</dc:creator>
      <dc:date>2019-02-19T19:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with other values depending on frequency</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536889#M16562</link>
      <description>&lt;P&gt;Can we generalize from the data you show, and assume that the blanks are always the second item for each ID? If so, then this approach ought to work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id;
    prev_visit_date=lag(visit_date);
    prev_age=lag(age);
    if last.id and not first.id and missing(age) then
        age = round(prev_age+0.5+(visit_date-prev_visit_date)/365);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If we can't make that assumption, then you need to clearly state the full set of assumptions needed regarding the setup of your data.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 20:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/536889#M16562</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-19T20:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with other values depending on frequency</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/537329#M16575</link>
      <description>Similar but different:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;prior_age = lag(age);&lt;BR /&gt;N_days = dif(visit_date) + 365/2;&lt;BR /&gt;if first.id=0 and age=. then age =&lt;BR /&gt;prior_age + int(n_days / 365) ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Also, consider using a denominator of 365.25 instead of 365.</description>
      <pubDate>Thu, 21 Feb 2019 07:21:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Fill-missing-values-with-other-values-depending-on-frequency/m-p/537329#M16575</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-21T07:21:30Z</dc:date>
    </item>
  </channel>
</rss>

