From: sas analysis on
Hi All,

I have scores for each subject at various time points. In certain
visits, scores were missing but in others recorded.
How can I input scores where missing based on the previous score. and
when a new score is recorded it remains and the following that are
missing take its value. This is a large dataset with more than 10000
observations. I have tried retain with first.subject code.

This is how the data looks:

Subject Score
1 2.8
1 .
1 3.5
1 .
1 4.0
2 2.2
2 .
2 .
2 2.3
2 .
4 5.5
4 5.7
4 .
4 .
4 4.6
4 .


This is how I want the data to look:
Subject Score
1 2.8
1 2.8
1 3.5
1 3.5
1 4.0
2 2.2
2 2.2
2 2.2
2 2.3
2 2.3
4 5.5
4 5.7
4 5.7
4 5.7
4 4.6
4 4.6


This is what I am trying to code:
data x;
set y;
retain scores;
if first.scores then score2;
else score2=scores;
run;

any ideas would be great?
Thanks!

From: Tom Abernathy on
You want to retain the NEW variable.
Also usually your data will be for multiple subjects/samples/cases so
you will not want to carry the last value from the previous subject to
the next subject.

data new;
set old (rename=(score=_score));
by id;
retain score;
if first.id or (_score ne .) then score=_score;
run;




On Mar 16, 5:10 pm, sas analysis <sasanaly...(a)gmail.com> wrote:
> Hi All,
>
> I have scores for each subject at various time points. In certain
> visits, scores were missing but in others recorded.
> How can I input scores where missing based on the previous score. and
> when a new score is recorded it remains and the following that are
> missing take its value. This is a large dataset with more than 10000
> observations. I have tried retain with first.subject code.
>
> This is how the data looks:
>
> Subject        Score
> 1                    2.8
> 1                      .
> 1                    3.5
> 1                      .
> 1                    4.0
> 2                    2.2
> 2                      .
> 2                      .
> 2                    2.3
> 2                      .
> 4                    5.5
> 4                    5.7
> 4                     .
> 4                     .
> 4                   4.6
> 4                    .
>
> This is how I want the data to look:
> Subject        Score
> 1                    2.8
> 1                    2.8
> 1                    3.5
> 1                    3.5
> 1                    4.0
> 2                    2.2
> 2                    2.2
> 2                    2.2
> 2                    2.3
> 2                    2.3
> 4                    5.5
> 4                    5.7
> 4                    5.7
> 4                    5.7
> 4                    4.6
> 4                    4.6
>
> This is what I am trying to code:
> data x;
> set y;
> retain scores;
> if first.scores then score2;
> else score2=scores;
> run;
>
> any ideas would be great?
> Thanks!

From: sas analysis on
On Mar 16, 8:09 pm, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
> You want to retain the NEW variable.
> Also usually your data will be for multiple subjects/samples/cases so
> you will not want to carry the last value from the previous subject to
> the next subject.
>
> data new;
>   set old (rename=(score=_score));
>   by id;
>   retain score;
>   if first.id or (_score ne .) then score=_score;
> run;
>
> On Mar 16, 5:10 pm, sas analysis <sasanaly...(a)gmail.com> wrote:
>
>
>
> > Hi All,
>
> > I have scores for each subject at various time points. In certain
> > visits, scores were missing but in others recorded.
> > How can I input scores where missing based on the previous score. and
> > when a new score is recorded it remains and the following that are
> > missing take its value. This is a large dataset with more than 10000
> > observations. I have tried retain with first.subject code.
>
> > This is how the data looks:
>
> > Subject        Score
> > 1                    2.8
> > 1                      .
> > 1                    3.5
> > 1                      .
> > 1                    4.0
> > 2                    2.2
> > 2                      .
> > 2                      .
> > 2                    2.3
> > 2                      .
> > 4                    5.5
> > 4                    5.7
> > 4                     .
> > 4                     .
> > 4                   4.6
> > 4                    .
>
> > This is how I want the data to look:
> > Subject        Score
> > 1                    2.8
> > 1                    2.8
> > 1                    3.5
> > 1                    3.5
> > 1                    4.0
> > 2                    2.2
> > 2                    2.2
> > 2                    2.2
> > 2                    2.3
> > 2                    2.3
> > 4                    5.5
> > 4                    5.7
> > 4                    5.7
> > 4                    5.7
> > 4                    4.6
> > 4                    4.6
>
> > This is what I am trying to code:
> > data x;
> > set y;
> > retain scores;
> > if first.scores then score2;
> > else score2=scores;
> > run;
>
> > any ideas would be great?
> > Thanks!- Hide quoted text -
>
> - Show quoted text -

Thanks!

Also, I was wondering is there a way to get a weighted average of both
scores (between the one before and right after)?