<?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: Need help to impute NULL with value from the same ID in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/920205#M41221</link>
    <description>Thank you very much for your helpful tips and solution!&amp;nbsp;</description>
    <pubDate>Wed, 13 Mar 2024 21:56:12 GMT</pubDate>
    <dc:creator>tan-wongv</dc:creator>
    <dc:date>2024-03-13T21:56:12Z</dc:date>
    <item>
      <title>Need help to impute NULL with value from the same ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918536#M41114</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tanwongv_0-1709273067135.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94287i489512E6D1D04377/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tanwongv_0-1709273067135.png" alt="tanwongv_0-1709273067135.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have a dataset with multiple record dates per ID (DMRN). As you can see that the sample with DMRN = 16 has Null for tobacco_user at the first visit. I would like to impute the NULL with the value from other visits (In this case it will be Never). Can anyone help me with the SAS code? I am very new to SAS program and still have so many things to learn. Thank you very much.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 06:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918536#M41114</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-03-01T06:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to impute NULL with value from the same ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918541#M41115</link>
      <description>&lt;P&gt;What is your rule for replacing the "null" with another value when there are two or more non-null values?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 07:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918541#M41115</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-01T07:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to impute NULL with value from the same ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918546#M41116</link>
      <description>&lt;P&gt;My aim is to analyze the value at patient's first visit, and NULL in this survey is counted as a missing value at a specific visit.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 09:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918546#M41116</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-03-01T09:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to impute NULL with value from the same ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918549#M41117</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464169"&gt;@tan-wongv&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My aim is to analyze the value at patient's first visit, and NULL in this survey is counted as a missing value at a specific visit.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Does not answer the question about what to do with two, or more, different non-null responses.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 09:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918549#M41117</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-01T09:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to impute NULL with value from the same ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918556#M41118</link>
      <description>&lt;P&gt;Welcome to the SAS Communities.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your screenshot doesn't show such a case but "in theory" there could also be "NULL" after a date where you had another value. I assume in such a case you would just want to repeat the last earlier value that wasn't "NULL" ...which then gets us into a situation where we need logic for both a look ahead (for the first row per dmrn) and a look behind once there was a value other than "NULL".&lt;/P&gt;
&lt;P&gt;The SAS data step just iterates over the rows from a source table which makes a look behind easy because that's a row you've already read in an earlier iteration. You can use the lag() function or the retain statement for this.&lt;/P&gt;
&lt;P&gt;A look-ahead is a bit harder to code for because you need information from a source row that hasn't been read yet. In below sample code I'm first creating a table "inter" that contains the first row from "have" per dmnr where the value is not "NULL". I then use the MERGE statement for this "look ahead". ...you will need to read-up a bit how the SAS data step MERGE statement works when there are same named variables in more than one of the source tables (=the value from which table wins for same named variables).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input dmrn dx_date:date9. tobacco_user $;
  have_tobacco_user=tobacco_user;
  format dx_date date9.;
  datalines;
16 01jan2024 NULL
16 02jan2024 Never
16 03jan2024 NULL
16 04jan2024 NULL
16 05jan2024 Quit
16 07jan2024 NULL
;

data inter(keep=dmrn tobacco_user);
  set have;
  by dmrn dx_date;
  retain out_flg;
  if first.dmrn then out_flg=0;
  if out_flg=1 then delete;
  if tobacco_user ne 'NULL' then
    do;
      output;
      out_flg=1;
    end;
run;

data want;
  merge have inter;
  by dmrn;
  retain r_tobacco_user;
  if tobacco_user ne 'NULL'   then r_tobacco_user=tobacco_user;
  else if tobacco_user='NULL' then tobacco_user=r_tobacco_user;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Going forward and to help us help you: Please post sample data not as screenshot but a data step code that creates such data (similar to the "data have" code above).&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 10:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/918556#M41118</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-01T10:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to impute NULL with value from the same ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/920205#M41221</link>
      <description>Thank you very much for your helpful tips and solution!&amp;nbsp;</description>
      <pubDate>Wed, 13 Mar 2024 21:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-to-impute-NULL-with-value-from-the-same-ID/m-p/920205#M41221</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-03-13T21:56:12Z</dc:date>
    </item>
  </channel>
</rss>

