replace missing values

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

replace missing values

drfg2008
I have a missing data problem. The data is as following (variable name= Team1):

****************
Team1
1
.
.
.
2
.
.
1
.
.
.
.
5
.
.
.

************

Now, I would like to fill the (system-) missings with the value on top of them like that:

****************
Team1
1
1
1
1
2
2
2
1
1
1
1
1
5
5
5
5
************

The problem is that there is not always the same number of missings, but sometimes 2 missings, sometimes 3, 4 or even more.

I found a complicated and clumsy solution with a lot of IFs ... and lags. Isn't there an elegant solution to the problem?

Frank
Dr. Frank Gaeth

Reply | Threaded
Open this post in threaded view
|

Re: replace missing values

Marta Garcia-Granero
Hi:

Not tested (from memory):

If missing(team1) team1=lag(team1).
exe.

The EXE is not really necessary (*), unless you want to check
immediately that the result is OK.

Best regards,
Marta GG

(*) Here's to you, Richard (Ristow) ;)


El 27/03/2012 14:27, drfg2008 escribió:

> I have a missing data problem. The data is as following (variable name=
> Team1):
>
> ****************
> Team1
> 1
> .
> .
> .
> 2
> .
> .
> 1
> .
> .
> .
> .
> 5
> .
> .
> .
>
> ************
>
> Now, I would like to fill the (system-) missings with the value on top of
> them like that:
>
> ****************
> Team1
> 1
> 1
> 1
> 1
> 2
> 2
> 2
> 1
> 1
> 1
> 1
> 1
> 5
> 5
> 5
> 5
> ************
>
> The problem is that there is not always the same number of missings, but
> sometimes 2 missings, sometimes 3, 4 or even more.
>
> I found a complicated and clumsy solution with a lot of IFs ... and lags.
> Isn't there an elegant solution to the problem?
>
> Frank
>
> -----
> Dr. Frank Gaeth
> FU-Berlin
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/replace-missing-values-tp5597687p5597687.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: replace missing values

Dawn Wiest
Frank,
 
This is the syntax I typically use to solve the problem you present (I've added your variable team1 at the DO REPEAT line):

SET ERRORS=no.
DO IF $CASENUM  >1.
DO REPEAT v=   Team1.
IF LEN(RTRIM(v))=0 v=LAG(v).
IF MISSING(v) v=LAG(v).
END REPEAT PRINT.
END IF.
SET ERRORS=yes.
EXECUTE.

HTH
 
Dawn
 
 

>>> Marta García-Granero<[hidden email]> 3/27/2012 9:02 AM >>>
Hi:

Not tested (from memory):

If missing(team1) team1=lag(team1).
exe.

The EXE is not really necessary (*), unless you want to check
immediately that the result is OK.

Best regards,
Marta GG

(*) Here's to you, Richard (Ristow) ;)


El 27/03/2012 14:27, drfg2008 escribió:

> I have a missing data problem. The data is as following (variable name=
> Team1):
>
> ****************
> Team1
> 1
> .
> .
> .
> 2
> .
> .
> 1
> .
> .
> .
> .
> 5
> .
> .
> .
>
> ************
>
> Now, I would like to fill the (system-) missings with the value on top of
> them like that:
>
> ****************
> Team1
> 1
> 1
> 1
> 1
> 2
> 2
> 2
> 1
> 1
> 1
> 1
> 1
> 5
> 5
> 5
> 5
> ************
>
> The problem is that there is not always the same number of missings, but
> sometimes 2 missings, sometimes 3, 4 or even more.
>
> I found a complicated and clumsy solution with a lot of IFs ... and lags.
> Isn't there an elegant solution to the problem?
>
> Frank
>
> -----
> Dr. Frank Gaeth
> FU-Berlin
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/replace-missing-values-tp5597687p5597687.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: replace missing values

Marta Garcia-Granero
Dawn:

Just using:

IF MISSING(Team1) Team1=LAG(Team1).

Works OK (I finally started SPSS and tested my code).

No need to DO REPEATs and DO IFs.

Best regards,
Marta GG

El 27/03/2012 15:15, Dawn Wiest escribió:
Frank,
This is the� syntax I typically use to solve the problem you present (I've added your variable team1 at the DO REPEAT line):

SET ERRORS=no.
DO IF $CASENUM� >1.
DO REPEAT v=� � � Team1.
IF LEN(RTRIM(v))=0 v=LAG(v).
IF MISSING(v) v=LAG(v).
END REPEAT PRINT.
END IF.
SET ERRORS=yes.
EXECUTE.

HTH
Dawn

>>> Marta García-Granero[hidden email] 3/27/2012 9:02 AM >>>
Hi:

Not tested (from memory):

If missing(team1) team1=lag(team1).
exe.

The EXE is not really necessary (*), unless you want to check
immediately that the result is OK.

Best regards,
Marta GG

(*) Here's to you, Richard (Ristow) ;)


El 27/03/2012 14:27, drfg2008 escribió:
> I have a missing data problem. The data is as following (variable name=
> Team1):
>
> ****************
> Team1
> 1
> .
> .
> .
> 2
> .
> .
> 1
> .
> .
> .
> .
> 5
> .
> .
> .
>
> ************
>
> Now, I would like to fill the (system-) missings with the value on top of
> them like that:
>
> ****************
> Team1
> 1
> 1
> 1
> 1
> 2
> 2
> 2
> 1
> 1
> 1
> 1
> 1
> 5
> 5
> 5
> 5
> ************
>
> The problem is that there is not always the same number of missings, but
> sometimes 2 missings, sometimes 3, 4 or even more.
>
> I found a complicated and clumsy solution with a lot of IFs ... and lags.
> Isn't there an elegant solution to the problem?
>
> Frank
>
> -----
> Dr. Frank Gaeth
> FU-Berlin
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/replace-missing-values-tp5597687p5597687.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: replace missing values

Dawn Wiest
Thanks, Marta.  Good to know!
 
Dawn
 

>>> Marta García-Granero<[hidden email]> 3/27/2012 9:21 AM >>>
Dawn:

Just using:

IF MISSING(Team1) Team1=LAG(Team1).

Works OK (I finally started SPSS and tested my code).

No need to DO REPEATs and DO IFs.

Best regards,
Marta GG

El 27/03/2012 15:15, Dawn Wiest escribió:
Frank,
This is the syntax I typically use to solve the problem you present (I've added your variable team1 at the DO REPEAT line):

SET ERRORS=no.
DO IF $CASENUM >1.
DO REPEAT v= Team1.
IF LEN(RTRIM(v))=0 v=LAG(v).
IF MISSING(v) v=LAG(v).
END REPEAT PRINT.
END IF.
SET ERRORS=yes.
EXECUTE.

HTH
Dawn

>>> Marta García-Granero[hidden email] 3/27/2012 9:02 AM >>>
Hi:

Not tested (from memory):

If missing(team1) team1=lag(team1).
exe.

The EXE is not really necessary (*), unless you want to check
immediately that the result is OK.

Best regards,
Marta GG

(*) Here's to you, Richard (Ristow) ;)


El 27/03/2012 14:27, drfg2008 escribió:

> I have a missing data problem. The data is as following (variable name=
> Team1):
>
> ****************
> Team1
> 1
> .
> .
> .
> 2
> .
> .
> 1
> .
> .
> .
> .
> 5
> .
> .
> .
>
> ************
>
> Now, I would like to fill the (system-) missings with the value on top of
> them like that:
>
> ****************
> Team1
> 1
> 1
> 1
> 1
> 2
> 2
> 2
> 1
> 1
> 1
> 1
> 1
> 5
> 5
> 5
> 5
> ************
>
> The problem is that there is not always the same number of missings, but
> sometimes 2 missings, sometimes 3, 4 or even more.
>
> I found a complicated and clumsy solution with a lot of IFs ... and lags.
> Isn't there an elegant solution to the problem?
>
> Frank
>
> -----
> Dr. Frank Gaeth
> FU-Berlin
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/replace-missing-values-tp5597687p5597687.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: replace missing values

drfg2008
In reply to this post by Marta Garcia-Granero
Thanks, great.
Dr. Frank Gaeth