<?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: Filling missing values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599448#M16501</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202889"&gt;@dapenDaniel&lt;/a&gt;&amp;nbsp; &amp;nbsp;If there is only one distinct ID2 for an ID1 group that you clarified earlier, you are basically filling in the blanks right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case , you could take advantage of the automatic remerge of PROC SQL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID1 $ ID2 $;
infile datalines missover;
datalines;
10001A       
10001A       
10001A AAA111
10001A AAA111
10001A AAA111
10001A AAA111
10001A       
10001A       
10001A       
10001B       
10001B       
10001B AAA111
10001B AAA111
10001B AAA111
10001B AAA111
10001B       
10001B       
10001B       
;
proc sql;
create table want(drop=_id2) as
select *,max(_ID2) as ID2
from have(rename=id2=_id2)
group by id1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2019 20:47:48 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-25T20:47:48Z</dc:date>
    <item>
      <title>Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599236#M16471</link>
      <description>&lt;P&gt;Hi, I have a data set like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ID2&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AAA111&lt;/P&gt;&lt;P&gt;10001A&lt;/P&gt;&lt;P&gt;10001A&lt;/P&gt;&lt;P&gt;10001A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I would like to fill the missing value. As long as the ID1 is the same, fill the missing value with the available value. The data set I want is below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ID2&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AAA111&lt;/P&gt;&lt;P&gt;10001A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AAA111&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone tell me what code I need to use? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599236#M16471</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2019-10-25T06:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599239#M16472</link>
      <description>&lt;P&gt;Yes. But what if you have multiple values in ID2 for ID1=10001A?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599239#M16472</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-25T06:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599241#M16473</link>
      <description>&lt;P&gt;For ID1=10001A, there is only one ID2&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599241#M16473</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2019-10-25T06:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599242#M16474</link>
      <description>&lt;P&gt;I am aware. For simple data like this, you can do something like below. I added another group to ID1 to demonstrate that it handles multiple groups&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID1 $ ID2 $;
infile datalines missover;
datalines;
10001A       
10001A       
10001A AAA111
10001A AAA111
10001A AAA111
10001A AAA111
10001A       
10001A       
10001A       
10001B       
10001B       
10001B AAA111
10001B AAA111
10001B AAA111
10001B AAA111
10001B       
10001B       
10001B       
;

data want(drop=_);
    do until (last.ID1);
        set have;
        by ID1;
        if not missing(ID2) then _=ID2;
    end;
    do until (last.ID1);
        set have;
        by ID1;
        if missing(ID2) then ID2=_;
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID1      ID2
10001A   AAA111
10001A   AAA111
10001A   AAA111
10001A   AAA111
10001A   AAA111
10001A   AAA111
10001A   AAA111
10001A   AAA111
10001A   AAA111
10001B   AAA111
10001B   AAA111
10001B   AAA111
10001B   AAA111
10001B   AAA111
10001B   AAA111
10001B   AAA111
10001B   AAA111
10001B   AAA111&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599242#M16474</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-25T06:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599243#M16475</link>
      <description>&lt;P&gt;Here an approach using a hash lookup.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then 
    do;
      dcl hash h1(dataset:'have(keep=id1 id2 where=(not missing(id2))))');
      h1.defineKey('id1');
      h1.defineData('id2');
      h1.defineDone();
    end;
  set have;
  if missing(id2) then h1.find();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599243#M16475</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-25T06:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599267#M16477</link>
      <description>&lt;P&gt;alternately please try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID1 $ ID2 $;
infile datalines missover;
datalines;
10001A       
10001A       
10001A AAA111
10001A AAA111
10001A AAA111
10001A AAA111
10001A       
10001A       
10001A       
10001B       
10001B       
10001B AAA111
10001B AAA111
10001B AAA111
10001B AAA111
10001B       
10001B       
10001B       
;

proc sort data=have;
by id1 descending id2;
run;

data want;
length id2 $10.;
set have(rename=(id2=_id2));
by id1 ;
retain id2;
if first.id1 then id2='';
if _id2 ne '' then id2=_id2;
keep id1 id2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Oct 2019 09:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599267#M16477</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-10-25T09:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599279#M16483</link>
      <description>&lt;P&gt;I would suggest taking advantage of how the MERGE …. BY statement combination works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID1 $ ID2 $;
infile datalines missover;
datalines;
10001A       
10001A       
10001A AAA111
10001A AAA111
10001A AAA111
10001A AAA111
10001A       
10001A       
10001A       
10001B       
10001B       
10001B AAA111
10001B AAA111
10001B AAA111
10001B AAA111
10001B       
10001B       
10001B       
;

data want;
  merge have (drop=id2) 
        have (keep=id1 id2 where=(id2^='')); /*Edited change */
  by id1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value for ID2 is derived only from the second invocation of HAVE.&amp;nbsp; That invocation is shorter than the first, because it is limited to cases with non-missing ID2.&amp;nbsp; When you merge two datasets (i.e. 2 uses of HAVE in this case) with BY groups, then the last value for variables that are uniquely in the shorter by-group will be propagated through all the "extra" observations in the longer by-group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this assumes that all the non-missing ID2 records for a given ID1 have only a single value.&amp;nbsp; I have also edited the second invocation of HAVE to keep only variables ID1 and ID2.&amp;nbsp; This will ensure the any other variables will get their values from the first HAVE.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 11:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599279#M16483</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-25T11:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599289#M16484</link>
      <description>&lt;P&gt;another try:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.ID1 as ID1, COALESCE(a.ID2,b.ID2) as ID2&lt;BR /&gt;from&lt;BR /&gt;have a&lt;BR /&gt;left join&lt;BR /&gt;(select distinct ID1,ID2 from have where ID2 IS NOT MISSING) b&lt;BR /&gt;ON a.ID1=b.ID1;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 11:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599289#M16484</guid>
      <dc:creator>pradeepalankar</dc:creator>
      <dc:date>2019-10-25T11:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599448#M16501</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202889"&gt;@dapenDaniel&lt;/a&gt;&amp;nbsp; &amp;nbsp;If there is only one distinct ID2 for an ID1 group that you clarified earlier, you are basically filling in the blanks right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case , you could take advantage of the automatic remerge of PROC SQL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID1 $ ID2 $;
infile datalines missover;
datalines;
10001A       
10001A       
10001A AAA111
10001A AAA111
10001A AAA111
10001A AAA111
10001A       
10001A       
10001A       
10001B       
10001B       
10001B AAA111
10001B AAA111
10001B AAA111
10001B AAA111
10001B       
10001B       
10001B       
;
proc sql;
create table want(drop=_id2) as
select *,max(_ID2) as ID2
from have(rename=id2=_id2)
group by id1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 20:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filling-missing-values/m-p/599448#M16501</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-25T20:47:48Z</dc:date>
    </item>
  </channel>
</rss>

