<?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 in missings with none missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537962#M148046</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input session_id  device_name $ time_sum ;
cards;
    1             .          .
    1          desktop       .
    1             .          12
    1             .          .
    2             .          11
    2             .          .
    2          mobile        .  
    3          desktop       10
    3             .          10
	;
data want;
 merge have(keep= session_id)
 have(keep= session_id device_name where=(device_name is not missing) )
 have(keep= session_id time_sum  where=(time_sum  is not missing) );
by session_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 23 Feb 2019 12:27:39 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-02-23T12:27:39Z</dc:date>
    <item>
      <title>Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537273#M147728</link>
      <description>&lt;P&gt;How to fill in missings with the non-missing value for each session_id group? Here device_name(character) and time_sum(numeric) have missings for each session_id group. The non-missing only appear once for each group, and I'm hoping to repeat the non-missing value by the group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;session_id  device_name time_sum
    1             .          .
    1          desktop       .
    1             .          12
    1             .          .&lt;BR /&gt;    2             .          11&lt;BR /&gt;    2             .          .&lt;BR /&gt;    2          mobile        .  &lt;BR /&gt;    3          desktop       10&lt;BR /&gt;    3             .          10&lt;BR /&gt;  &lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Hoping to have this outcome:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;session_id  device_name time_sum
    1          desktop       12
    1          desktop       12
    1          desktop       12
    1          desktop       12&lt;BR /&gt;    2           mobile       11&lt;BR /&gt;    2           mobile       11&lt;BR /&gt;    2           mobile       11 &lt;BR /&gt;    3          desktop       10&lt;BR /&gt;    3          desktop       10&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;Grateful for any input!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 02:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537273#M147728</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-02-21T02:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537279#M147734</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input session_id  device_name $ time_sum ;
cards;
    1             .          .
    1          desktop       .
    1             .          12
    1             .          .
    2             .          11
    2             .          .
    2          mobile        .  
    3          desktop       10
    3             .          10
	;

proc sql;
create table want as
select 	a.session_id, device_name, time_sum
from have(keep=session_id) a inner join
(select session_id,max(device_name) as device_name, max(time_sum) as time_sum from have group by session_id) b
on a.session_id=b.session_id
order by  session_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 02:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537279#M147734</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-21T02:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537288#M147742</link>
      <description>&lt;P&gt;There are many ways to do this...here is but one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You also don't say what you want if there are duplicate data within a session_id, for example session_id=2 and time_sum in (11,99).&amp;nbsp; In my code, the first value wins.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input session_id :8. device_name :$10. time_sum :8.;
   datalines;
    1             .          .
    1          desktop       .
    1             .          12
    1             .          .
    2             .          11
    2             .          .
    2          mobile        .  
    3          desktop       10
    3             .          10
;
run; 

data want;
   if 0 then set have;
   %let _hashnum_=0;
   %hash_define(data=have,keys=session_id,vars=device_name,where=device_name is not missing);
   %hash_define(data=have,keys=session_id,vars=time_sum,where=time_sum is not missing);
   set have;
   %hash_lookup;
   drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Download %hash_define and %hash_lookup (and any supporting macros, such as %parmv) from here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/tree/master/Macro" target="_self"&gt;https://github.com/scottbass/SAS/tree/master/Macro&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 03:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537288#M147742</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-21T03:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537293#M147747</link>
      <description>Two short steps?&lt;BR /&gt;&lt;BR /&gt;Data temp;&lt;BR /&gt;Update have (obs=0) have;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;update temp have;&lt;BR /&gt;by id;&lt;BR /&gt;output;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 21 Feb 2019 03:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537293#M147747</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-21T03:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537302#M147751</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; thank you for the prompt response and efficient coding. Just an add-on question, if I want to carry over other variables that do not need filling missings, how should I add them to the code?</description>
      <pubDate>Thu, 21 Feb 2019 04:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537302#M147751</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-02-21T04:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537304#M147752</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; I have a column that carries over unique observation numbers that have no missings.</description>
      <pubDate>Thu, 21 Feb 2019 04:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537304#M147752</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-02-21T04:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537305#M147753</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp; The carry over variables should be part of&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;session_id&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; a&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I just took your sample, but of course you could have session_id and the carry over variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;however&amp;nbsp; this part below&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; session_id&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;max&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;device_name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; as device_name&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;max&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;time_sum&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; as time_sum &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; have &lt;SPAN class="token keyword"&gt;group&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; session_id&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; b&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;should only include sesion_id and vars that need filling.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope you are able to follow&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 04:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537305#M147753</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-21T04:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in missings with none missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537962#M148046</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input session_id  device_name $ time_sum ;
cards;
    1             .          .
    1          desktop       .
    1             .          12
    1             .          .
    2             .          11
    2             .          .
    2          mobile        .  
    3          desktop       10
    3             .          10
	;
data want;
 merge have(keep= session_id)
 have(keep= session_id device_name where=(device_name is not missing) )
 have(keep= session_id time_sum  where=(time_sum  is not missing) );
by session_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Feb 2019 12:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-missings-with-none-missing/m-p/537962#M148046</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-02-23T12:27:39Z</dc:date>
    </item>
  </channel>
</rss>

