[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Filling Missing Values
From:       Richard DeVenezia <rdevenezia () GMAIL ! COM>
Date:       2020-10-26 3:42:28
Message-ID: CACT-pRzOKcBpkcSQZaRq=TzSrjvmOyGpCB2SQT=m+BjbfmgVpQ () mail ! gmail ! com
[Download RAW message or body]

As answered in community

data want;
  set have;
  by  id;

  var_a = coalesceC (var_a, ifc (last.id and not first.id, lag(var_a), ''));
run;

--
Richard

On Sun, Oct 25, 2020 at 12:50 AM Randy <randistan69@hotmail.com> wrote:

> Dear All:
>
> My data is as follows:
>
> ID       VAR_A
> 1            MF
> 1            MF
> 1            MF
> 2            HUF
> 2
> 2           HUF
> 2
> 3
> 3
> 3
> 4
> 4           I
> 4           I
> 4           I
> 4           NRI
> 4
>
> I want my data to look as follow -- where the rule is that the last
> observation is missing should be the previous non-missing observation.
>
> ID       VAR_A
> 1            MF
> 1            MF
> 1            MF
> 2            HUF
> 2
> 2           HUF
> 2           HUF
> 3
> 3
> 3
> 4
> 4           I
> 4           I
> 4           I
> 4           NRI
> 4           NRI
>

[Attachment #3 (text/html)]

<div dir="ltr"><div dir="ltr"><div class="gmail_default" \
style="font-family:arial,sans-serif">As answered in community</div><div \
class="gmail_default" style="font-family:arial,sans-serif"><br></div><div \
class="gmail_default"><div class="gmail_default"><font face="monospace">data \
want;</font></div><div class="gmail_default"><font face="monospace">   set \
have;</font></div><div class="gmail_default"><font face="monospace">   by   \
id;</font></div><div class="gmail_default"><font \
face="monospace"><br></font></div><div class="gmail_default"><font face="monospace">  \
var_a = coalesceC (var_a, ifc (<a href="http://last.id">last.id</a> and not <a \
href="http://first.id">first.id</a>, lag(var_a), &#39;&#39;));</font></div><div \
class="gmail_default"><font face="monospace">run;</font></div></div><div \
class="gmail_default" style="font-family:arial,sans-serif"><br></div><div \
class="gmail_default" style="font-family:arial,sans-serif">--</div><div \
class="gmail_default" \
style="font-family:arial,sans-serif">Richard</div></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 25, 2020 at 12:50 \
AM Randy &lt;<a href="mailto:randistan69@hotmail.com">randistan69@hotmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear All:<br> <br>
My data is as follows:<br>
<br>
ID           VAR_A<br>
1                  MF<br>
1                  MF<br>
1                  MF<br>
2                  HUF<br>
2                 <br>
2                 HUF<br>
2<br>
3              <br>
3<br>
3<br>
4<br>
4                 I<br>
4                 I<br>
4                 I<br>
4                 NRI<br>
4 <br>
<br>
I want my data to look as follow -- where the rule is that the last observation is \
missing should be the previous non-missing observation.<br> <br>
ID           VAR_A<br>
1                  MF<br>
1                  MF<br>
1                  MF<br>
2                  HUF<br>
2                 <br>
2                 HUF<br>
2                 HUF<br>
3              <br>
3<br>
3<br>
4<br>
4                 I<br>
4                 I<br>
4                 I<br>
4                 NRI<br>
4                 NRI<br>
</blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic