lag function for system missing in recode

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

lag function for system missing in recode

charlene thornton
Hi

I want to recode data. There is a date in a case followed by system missing in the cases below. I want to recode so that the system missing cells = the date above. eg

16th Aug 2009
.
.
.
.
19th August 2008
.
.
I have been trying to do this with the SYSMIS and lag function in recode - but I continue to get error messages. I am obviously a novice to writing script. Can someone please help!
Reply | Threaded
Open this post in threaded view
|

Re: lag function for system missing in recode

Bruce Weaver
Administrator
How is the variable holding the date formatted?  If the values are as you show below, I wonder if it is a string rather than a date format.  Please post your syntax too.


charlene thornton wrote
Hi

I want to recode data. There is a date in a case followed by system missing in the cases below. I want to recode so that the system missing cells = the date above. eg

16th Aug 2009
.
.
.
.
19th August 2008
.
.
I have been trying to do this with the SYSMIS and lag function in recode - but I continue to get error messages. I am obviously a novice to writing script. Can someone please help!
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: lag function for system missing in recode

Garry Gelade
Hi Charlene,

Use MISSING() and LAG() as follows:

DATA LIST LIST /mydate (DATE).
BEGIN DATA
16-Aug-2009
,
,
19-Aug-2009
,
,
,
END DATA.

IF MISSING(mydate) mydate =LAG(mydate).
EXECUTE.
LIST.

    mydate

16-AUG-2009
16-AUG-2009
16-AUG-2009
19-AUG-2009
19-AUG-2009
19-AUG-2009
19-AUG-2009


Number of cases read:  7    Number of cases listed:  7

Garry Gelade
============================================================================
==

charlene thornton wrote:

>
> Hi
>
> I want to recode data. There is a date in a case followed by system
> missing in the cases below. I want to recode so that the system missing
> cells = the date above. eg
>
> 16th Aug 2009
> .
> .
> .
> .
> 19th August 2008
> .
> .
> I have been trying to do this with the SYSMIS and lag function in recode -
> but I continue to get error messages. I am obviously a novice to writing
> script. Can someone please help!
>


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/lag-function-for-system-missin
g-in-recode-tp4671831p4672424.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: lag function for system missing in recode

Richard Ristow
Sorry -- just want to remind folks from time to time.

At 01:13 PM 8/6/2011, Garry Gelade wrote precisely the right solution:

>IF MISSING(mydate) mydate =LAG(mydate).
>EXECUTE.
>LIST.

EXCEPT that the EXECUTE is not needed. Its only function is to force
the data to be read an extra, superfluous time -- use multiple
EXECUTEs when you have a big file, and you can drag your processing a good bit.

It isn't semantically harmless, either. Wasn't there a recent query
that posted code that didn't work because it used scratch variables,
and interposed EXECUTE statements that lost them?

=====================
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: lag function for system missing in recode

Bruce Weaver
Administrator
Re saving processing time, a few years ago a student here was computing a bunch of new variables etc on a file with millions of records.  The COMPUTE statements were generated by pasting from the GUI, and because the default setting had not been changed, there was an EXECUTE after each one.  The job took 10 or 12 hours, IIRC.  After I removed all the unnecessary EXECUTE lines (plus a few other changes), we got it down to a few minutes.  ;-)


Richard Ristow wrote
Sorry -- just want to remind folks from time to time.

At 01:13 PM 8/6/2011, Garry Gelade wrote precisely the right solution:

>IF MISSING(mydate) mydate =LAG(mydate).
>EXECUTE.
>LIST.

EXCEPT that the EXECUTE is not needed. Its only function is to force
the data to be read an extra, superfluous time -- use multiple
EXECUTEs when you have a big file, and you can drag your processing a good bit.

It isn't semantically harmless, either. Wasn't there a recent query
that posted code that didn't work because it used scratch variables,
and interposed EXECUTE statements that lost them?

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: lag function for system missing in recode

David Marso
Administrator
Yep!  EXECUTE sucks!  Better to do a desc or something if/when you need to pass the data.  At least you get some info from the pass.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: lag function for system missing in recode

charlene thornton
In reply to this post by charlene thornton
Thank you for answering my query - very grateful for the assistance