LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2009)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 2 Sep 2009 09:50:57 -0500
Reply-To:   "Peck, Jon" <peck@spss.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   "Peck, Jon" <peck@spss.com>
Subject:   Re: deleting/marking a record using a lag function
Comments:   To: John McConnell <jmcconnell@analyticalpeople.com>
In-Reply-To:   A<26829C93A04E80468FD5C21649477056012BF021@be15.exg4.exghost.com>
Content-Type:   text/plain; charset="utf-8"

If you have version 17 or later, note that there is a new command, SHIFT VALUES, that allows you to copy either lag or lead values. It is Transform>Shift Values on the menus.

Regards, Jon Peck

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of John McConnell Sent: Wednesday, September 02, 2009 7:22 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: [SPSSX-L] deleting/marking a record using a lag function

Hi Tracy

Just focussing on that last block you've hit a restriction in which SPSS will only allow you to compute a value on the current case (not the previous one though - as you've seen lag() can check values on the previous cases).

So one suggestion would be to sort the file in reverse order so in effect the lag ends up looking forwards rather than backwards.

If we assume that you have a variable called row and that uniquely identifies each case in the current order sequentially (looks like you do but if you don't COMPUTE ROW=$CASENUM. Will get you that)

Then ... this is untested ... but should work

I'd first make the assignment...

do if admit0506=1 and lapse le 30. compute lst_svc=lag(lst_svc). end if. execute.

...then resort the file...

SORT CASES BY ROW(d).

... then make the selection the other way round

compute drop=0. do if lag(admit0506)=1 and lag(lapse) le 30. compute drop = 1. end if. execute.

Select if drop=1.

... to get the file back in the right order ...

SORT CASES BY ROW(a).

Hope this helps

John

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Tracy Hazelton Sent: 02 September 2009 01:03 To: SPSSX-L@LISTSERV.UGA.EDU Subject: deleting/marking a record using a lag function

row case Admit Last svc lagAdmit Admit0506 TimeLapse 1 22 7/29/09 9/8/09 . . . 2 22 11/4/07 11/17/07 7/29/09 . 620 days 3 22 10/5/05 11/3/07 11/4/07 1 1 day

Hi everyone, I have a large dataset in which each client can have multiple admits within a certain time period. I’ve used the lag function to calculate the lapse between opening dates and the last service date of the previous opening date in order to merge multiple admits together-my rule is if the time lapse is lt 30 days it’s the same admit. I used this code to get the table above: do if case=lag(case). compute LagOp = lag(opdate). end if. execute.

do if lag(case) = case. compute lapse=ABS(xdate.tday(lst_svc)-xdate.tday(lagOp)). end if.

I now want to get rid of row 2 above bc the time lapse between admits is too long and it’s not an admit from my original cohort (i.e. admit0506=1. How do I do this? I wanted to use this code but it’s giving me an error about “computing lag (drop)=0."

compute drop=1. do if admit0506=1 and lapse le 30. compute lag(drop) = 0. compute lst_svc=lag(lst_svc). end if. execute.

Select if drop=1.

Any help on how to delete this case would be greatly appreciated!! I have way too many records to do this mannually. Tracy

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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 LISTSERV@LISTSERV.UGA.EDU (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 LISTSERV@LISTSERV.UGA.EDU (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


Back to: Top of message | Previous page | Main SPSSX-L page