<?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 values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350477#M81471</link>
    <description>&lt;P&gt;Easiest would probably be to sort the data set in reverse order, and bring forward the most recent nonmissing value. &amp;nbsp;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id p descending nc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id p;&lt;/P&gt;
&lt;P&gt;retain new_mg new_mp;&lt;/P&gt;
&lt;P&gt;if first.p then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;new_mg=mg;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;new_mp=mp;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if mg &amp;gt; . then new_mg = mg;&lt;/P&gt;
&lt;P&gt;else mg = new_mg;&lt;/P&gt;
&lt;P&gt;if mp &amp;gt; . then new_mp = mp;&lt;/P&gt;
&lt;P&gt;else mp = new_mp;&lt;/P&gt;
&lt;P&gt;drop new_mg new_mp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always put the observations back into their original order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by id p nc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Apr 2017 11:57:48 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-04-17T11:57:48Z</dc:date>
    <item>
      <title>missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350474#M81470</link>
      <description>&lt;P&gt;hi&amp;nbsp;everybody,&lt;/P&gt;&lt;P&gt;I know that every time you find me the right solution, so I do not delay to contact you with my best regards.&lt;/P&gt;&lt;P&gt;I have a dataset as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; P &amp;nbsp;NC MG MP&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;2.3 &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;2.6 &amp;nbsp; 3.2&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;3.5 &amp;nbsp; 4.1&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.2&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.3&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4.3 &amp;nbsp; 3.5&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;3.5 &amp;nbsp; 3.2&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;4.1 &amp;nbsp; 3.3&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;5 &amp;nbsp; &amp;nbsp;4.0 &amp;nbsp; 3.3&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;3.6 &amp;nbsp; 4.1&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;3.4 &amp;nbsp; 4.0&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;3.4 &amp;nbsp; 3.9&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;3 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;4.2 &amp;nbsp; 4.2&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;3 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;4.3 &amp;nbsp; 4.2&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;3 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4.2 &amp;nbsp; 4.1&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;4.6 &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;4.8 &amp;nbsp; &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4.7 &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;4.3 &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ID represents an identifier,&lt;BR /&gt;P = an exercise number, can be 1, 2, 3 or 4.&lt;BR /&gt;NC: an order number of each test for the same ID and the same exercise number.&lt;BR /&gt;MG and MP are observations.&lt;BR /&gt;What I want is to replace the missing values of MG or MP with the next value if it exists or even with the next value after if the next value is also missing. Nothing changes if all the observations during the same exercise are missing, either for MG or MP.&lt;/P&gt;&lt;P&gt;Note that missing values If they exist are only observed in the two first observations for&amp;nbsp;each ID at each P.&lt;BR /&gt;The desired result is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; P &amp;nbsp;NC MG MP&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;2.3&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;3.2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;2.3 &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3.2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;2.6 &amp;nbsp; 3.2&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;3.5 &amp;nbsp; 4.1&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;4.3&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;1.2&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;4.3&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;2.3&lt;/P&gt;&lt;P&gt;M1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4.3 &amp;nbsp; 3.5&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3.5&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3.2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3.5&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3.2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;3.5 &amp;nbsp; 3.2&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;4.1 &amp;nbsp; 3.3&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;5 &amp;nbsp; &amp;nbsp;4.0 &amp;nbsp; 3.3&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3.6&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;4.1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;3.6 &amp;nbsp; 4.1&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;3.4 &amp;nbsp; 4.0&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;3.4 &amp;nbsp; 3.9&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;3 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;4.2 &amp;nbsp; 4.2&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;3 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;4.3 &amp;nbsp; 4.2&lt;/P&gt;&lt;P&gt;M2 &amp;nbsp; &amp;nbsp;3 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4.2 &amp;nbsp; 4.1&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;4.6 &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;4.8 &amp;nbsp; &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4.7 &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;M3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp;4 &amp;nbsp; &amp;nbsp;4.3 &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I count on your help, thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 11:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350474#M81470</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-04-17T11:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350477#M81471</link>
      <description>&lt;P&gt;Easiest would probably be to sort the data set in reverse order, and bring forward the most recent nonmissing value. &amp;nbsp;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id p descending nc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id p;&lt;/P&gt;
&lt;P&gt;retain new_mg new_mp;&lt;/P&gt;
&lt;P&gt;if first.p then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;new_mg=mg;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;new_mp=mp;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if mg &amp;gt; . then new_mg = mg;&lt;/P&gt;
&lt;P&gt;else mg = new_mg;&lt;/P&gt;
&lt;P&gt;if mp &amp;gt; . then new_mp = mp;&lt;/P&gt;
&lt;P&gt;else mp = new_mp;&lt;/P&gt;
&lt;P&gt;drop new_mg new_mp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always put the observations back into their original order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by id p nc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 11:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350477#M81471</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-17T11:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350489#M81473</link>
      <description>&lt;PRE&gt;
data have;
input ID  $   P  NC MG MP;
cards;
M1    1  1    .       .
M1    1  2    2.3   .
M1    1  3    2.6   3.2
M1    1  4    3.5   4.1
M1    2  1    .       1.2
M1    2  2    .       2.3
M1    2  3    4.3   3.5
M2    1  1    .       .
M2    1  2    .       .
M2    1  3    3.5   3.2
M2    1  4    4.1   3.3
M2    1  5    4.0   3.3
M2    2  1    .       .
M2    2  2    3.6   4.1
M2    2  3    3.4   4.0
M2    2  4    3.4   3.9
M2    3  1    4.2   4.2
M2    3  2    4.3   4.2
M2    3  3    4.2   4.1
M3    2  1    4.6   .
M3    2  2    4.8   .
M3    2  3    4.7   .
M3    2  4    4.3   .
;
run;

proc sort data=have;
 by ID   P  NC;
run;
data temp;
 set have;
 by ID     P ;
 retain _MG _MP;
 if first.P then call missing(_MG,_MP);
 if not missing(MG) then _MG=MG;
 if not missing(MP) then _MP=MP;
 drop MG MP;
run;

proc sort data=temp;
 by ID   P  descending NC;
run;
data want;
 set temp;
 by ID     P ;
 retain MG MP;
 if first.P then call missing(MG,MP);
 if not missing(_MG) then MG=_MG;
 if not missing(_MP) then MP=_MP;
 drop _:;
run;

proc sort data=want;
 by ID   P  NC;
run;


&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Apr 2017 13:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350489#M81473</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-17T13:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350655#M81527</link>
      <description>&lt;P&gt;Thank you very much, it works very well.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 21:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350655#M81527</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-04-17T21:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350661#M81530</link>
      <description>&lt;P&gt;It works well too, thanks to you and to Astounding for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 21:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350661#M81530</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-04-17T21:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350911#M81638</link>
      <description>&lt;P&gt;Oops I am late to the part,Just for fun and nothing more:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; _null_;&lt;/P&gt;&lt;P&gt;if _n_=&lt;STRONG&gt;1&lt;/STRONG&gt; then do;&lt;/P&gt;&lt;P&gt;if &lt;STRONG&gt;0&lt;/STRONG&gt; then set have;&lt;/P&gt;&lt;P&gt;declare hash myhash(multidata:'YES',ordered:'a');&lt;/P&gt;&lt;P&gt;myhash.definekey('id','p');&lt;/P&gt;&lt;P&gt;myhash.definedata('id','p','nc','mg','mp');&lt;/P&gt;&lt;P&gt;myhash.definedone( );&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;set have end=last;&lt;/P&gt;&lt;P&gt;by id p;&lt;/P&gt;&lt;P&gt;if ((missing(mp) and missing(mg)) or (missing(mp) or missing(mg))) and myhash.check() ne &lt;STRONG&gt;0&lt;/STRONG&gt; then rc=myhash.add();&lt;/P&gt;&lt;P&gt;else if myhash.check() ne &lt;STRONG&gt;0&lt;/STRONG&gt; and not missing(mp) and not missing(mg) then rc=myhash.add();&lt;/P&gt;&lt;P&gt;else if myhash.check()=&lt;STRONG&gt;0&lt;/STRONG&gt; and (missing(mp) and missing(mg)) then rc=myhash.add();&lt;/P&gt;&lt;P&gt;else if myhash.check()=&lt;STRONG&gt;0&lt;/STRONG&gt; and ((not missing(mp) and missing(mg)) or (missing(mp) and not missing(mg))) then&lt;/P&gt;&lt;P&gt;do;&lt;/P&gt;&lt;P&gt;_mg=mg;&lt;/P&gt;&lt;P&gt;_mp=mp;&lt;/P&gt;&lt;P&gt;_nc=nc;&lt;/P&gt;&lt;P&gt;rc=myhash.find();&lt;/P&gt;&lt;P&gt;if missing(mg) then mg=_mg;&lt;/P&gt;&lt;P&gt;if missing(mp) then mp=_mp;&lt;/P&gt;&lt;P&gt;myhash.replacedup();&lt;/P&gt;&lt;P&gt;rc=myhash.find_next();&lt;/P&gt;&lt;P&gt;do while(rc=&lt;STRONG&gt;0&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;if missing(mg) then mg=_mg;&lt;/P&gt;&lt;P&gt;if missing(mp) then mp=_mp;&lt;/P&gt;&lt;P&gt;myhash.replacedup();&lt;/P&gt;&lt;P&gt;rc=myhash.find_next();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;mg=_mg;&lt;/P&gt;&lt;P&gt;mp=_mp;&lt;/P&gt;&lt;P&gt;nc=_nc;&lt;/P&gt;&lt;P&gt;myhash.add();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else if myhash.check()=&lt;STRONG&gt;0&lt;/STRONG&gt; and not missing(mp) and not missing(mg) then do;&lt;/P&gt;&lt;P&gt;_mg=mg;&lt;/P&gt;&lt;P&gt;_mp=mp;&lt;/P&gt;&lt;P&gt;_nc=nc;&lt;/P&gt;&lt;P&gt;rc=myhash.find();&lt;/P&gt;&lt;P&gt;if missing(mg) then mg=_mg;&lt;/P&gt;&lt;P&gt;if missing(mp) then mp=_mp;&lt;/P&gt;&lt;P&gt;myhash.replacedup();&lt;/P&gt;&lt;P&gt;rc=myhash.find_next();&lt;/P&gt;&lt;P&gt;do while(rc=&lt;STRONG&gt;0&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;if missing(mg) then mg=_mg;&lt;/P&gt;&lt;P&gt;if missing(mp) then mp=_mp;&lt;/P&gt;&lt;P&gt;myhash.replacedup();&lt;/P&gt;&lt;P&gt;rc=myhash.find_next();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;mg=_mg;&lt;/P&gt;&lt;P&gt;mp=_mp;&lt;/P&gt;&lt;P&gt;nc=_nc;&lt;/P&gt;&lt;P&gt;myhash.add();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if last then rc=myhash.output(dataset:'want');&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sort&lt;/STRONG&gt; data=want;&lt;/P&gt;&lt;P&gt;by &amp;nbsp; id p nc;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 15:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/missing-values/m-p/350911#M81638</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-18T15:57:53Z</dc:date>
    </item>
  </channel>
</rss>

