<?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: missing data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233004#M42510</link>
    <description>&lt;P&gt;Long time no see!&amp;nbsp;I suppose Data step solution would be a lot more efficient/elegant, but I can't figure out one right now, so here is the Ugly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
input id$ count var1;
cards;
aa 1 20
aa 2 .
aa 3 30
bb 1 10
bb 2 .
bb 3 .
bb 4 20
cc 1 10
cc 2 .
cc 3 30
cc 4 .
cc 5 50
;
 
proc sql;
create table want as
select id, count, case when not missing(var1) then var1 else mean((select var1 from have where id=a.id and count &amp;lt; a.count and not missing(var1) having count=max(count)),
(select var1 from have where id=a.id and count &amp;gt; a.count and not missing (var1) having count=min(count))) end as var1
from have a
;
quit;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Nov 2015 00:43:10 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2015-11-04T00:43:10Z</dc:date>
    <item>
      <title>missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/232994#M42505</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;How could I get dataset WANT from HAVE? &amp;nbsp;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id$ count var1;&lt;BR /&gt;cards;&lt;BR /&gt;aa 1 20&lt;BR /&gt;aa 2 .&lt;BR /&gt;aa 3 30&lt;BR /&gt;bb 1 10&lt;BR /&gt;bb 2 .&lt;BR /&gt;bb 3 .&lt;BR /&gt;bb 4 20&lt;BR /&gt;cc 1 10&lt;BR /&gt;cc 2 .&lt;BR /&gt;cc 3 30&lt;BR /&gt;cc 4 .&lt;BR /&gt;cc 5 50&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;id count var1&lt;BR /&gt;aa 1 20&lt;BR /&gt;aa 2 25&lt;BR /&gt;aa 3 30&lt;BR /&gt;bb 1 10&lt;BR /&gt;bb 2 15&lt;BR /&gt;bb 3 15&lt;BR /&gt;bb 4 20&lt;BR /&gt;cc 1 10&lt;BR /&gt;cc 2 20&lt;BR /&gt;cc 3 30&lt;BR /&gt;cc 4 40&lt;BR /&gt;cc 5 50&lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2015 23:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/232994#M42505</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2015-11-03T23:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233004#M42510</link>
      <description>&lt;P&gt;Long time no see!&amp;nbsp;I suppose Data step solution would be a lot more efficient/elegant, but I can't figure out one right now, so here is the Ugly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
input id$ count var1;
cards;
aa 1 20
aa 2 .
aa 3 30
bb 1 10
bb 2 .
bb 3 .
bb 4 20
cc 1 10
cc 2 .
cc 3 30
cc 4 .
cc 5 50
;
 
proc sql;
create table want as
select id, count, case when not missing(var1) then var1 else mean((select var1 from have where id=a.id and count &amp;lt; a.count and not missing(var1) having count=max(count)),
(select var1 from have where id=a.id and count &amp;gt; a.count and not missing (var1) having count=min(count))) end as var1
from have a
;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2015 00:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233004#M42510</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-11-04T00:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233006#M42512</link>
      <description>&lt;P&gt;Also, long time, no see. Missed you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You appear to want to use two different methods for the 2nd and 3rd IDs. Is that really what you want, or something else?&lt;/P&gt;&lt;P&gt;If you want to use the same method, the following seems to come close:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC STDIZE data=have out=want method=mean missing=midrange reponly;&lt;BR /&gt;&amp;nbsp; var var1;&lt;BR /&gt;&amp;nbsp; by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 01:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233006#M42512</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-11-04T01:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233015#M42513</link>
      <description>&lt;P&gt;A data step solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id$ count var1;
cards;
aa 1 20
aa 2 .
aa 3 30
bb 1 10
bb 2 .
bb 3 .
bb 4 20
cc 1 10
cc 2 .
cc 3 30
cc 4 .
cc 5 50
;

data want0;
retain lastVar1;
set have; by id;
if first.id then call missing(lastVar1);
if missing(var1) then prevVar1 = lastVar1;
else lastVar1 = var1;
drop lastVar1;
run;

proc sort data=want0; by id descending count; run;

data want;
retain lastVar1;
set want0; by id;
if first.id then call missing(lastVar1);
if missing(var1) then var1 = mean(prevVar1, lastVar1);
else lastVar1 = var1;
drop lastVar1 prevVar1;
run;

proc sort data=want; by id count; run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2015 02:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233015#M42513</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-04T02:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233177#M42568</link>
      <description>&lt;P&gt;Hi Haikuo, Art, and PG,&lt;/P&gt;&lt;P&gt;Thank you very much for your great help!! I miss you guys too.&lt;/P&gt;&lt;P&gt;Best wishes!&lt;/P&gt;&lt;P&gt;Linlin&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 20:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-data/m-p/233177#M42568</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2015-11-04T20:44:40Z</dc:date>
    </item>
  </channel>
</rss>

