Finding and marking related cases

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

Finding and marking related cases

nessie
Hi,

I'm working with a dataset containing hospital stays and out patient contacts. Some of these are related to others and toghether they form a combined/aggregated stay. Others are just singel visits. One patient can visit the hospital several times and the cases are only related if they overlap in time. One aggregated stay can contain one or more stays and/or outpatient contacts before/in/after (or between combined) stays or just consecutive outpatient visits.

Are there any way to find the related cases and flag them with a matching "aggregate"-variable value?

Example syntax:

DATA LIST LIST /
case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.

LIST.

Here case 1, 3 and 5 are related from the same patient. Case 1 and 5 are consecutive stays and case 3 is an out-patient contact made during case 1. Case 7 is also the same patient, but not related to the same aggregated stay.

Case 2 and 6 has the same id and therefore represents the same patient, but they aren't related as the in/out variabels don't match.

Case 4 is just a singel stay.

(My real in/out variables are datetime variables).
Can you help me?

Best regards
Lars N.
Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

David Marso
Administrator
use SORT and then LAG and simple logic!
nessie wrote
Hi,

I'm working with a dataset containing hospital stays and out patient contacts. Some of these are related to others and toghether they form a combined/aggregated stay. Others are just singel visits. One patient can visit the hospital several times and the cases are only related if they overlap in time. One aggregated stay can contain one or more stays and/or outpatient contacts before/in/after (or between combined) stays or just consecutive outpatient visits.

Are there any way to find the related cases and flag them with a matching "aggregate"-variable value?

Example syntax:

DATA LIST LIST /
case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.

LIST.

Here case 1, 3 and 5 are related from the same patient. Case 1 and 5 are consecutive stays and case 3 is an out-patient contact made during case 1. Case 7 is also the same patient, but not related to the same aggregated stay.

Case 2 and 6 has the same id and therefore represents the same patient, but they aren't related as the in/out variabels don't match.

Case 4 is just a singel stay.

(My real in/out variables are datetime variables).
Can you help me?

Best regards
Lars N.
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: Finding and marking related cases

nessie
Thank's, I will look into it.

2014-05-19 11:50 GMT+02:00 David Marso [via SPSSX Discussion] <[hidden email]>:
use SORT and then LAG and simple logic!
nessie wrote
Hi,

I'm working with a dataset containing hospital stays and out patient contacts. Some of these are related to others and toghether they form a combined/aggregated stay. Others are just singel visits. One patient can visit the hospital several times and the cases are only related if they overlap in time. One aggregated stay can contain one or more stays and/or outpatient contacts before/in/after (or between combined) stays or just consecutive outpatient visits.

Are there any way to find the related cases and flag them with a matching "aggregate"-variable value?

Example syntax:

DATA LIST LIST /
case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.

LIST.

Here case 1, 3 and 5 are related from the same patient. Case 1 and 5 are consecutive stays and case 3 is an out-patient contact made during case 1. Case 7 is also the same patient, but not related to the same aggregated stay.

Case 2 and 6 has the same id and therefore represents the same patient, but they aren't related as the in/out variabels don't match.

Case 4 is just a singel stay.

(My real in/out variables are datetime variables).
Can you help me?

Best regards
Lars N.
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726130.html
To unsubscribe from Finding and marking related cases, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

David Marso
Administrator
Something like the following?
Note you may need to change the number of cases in the "lookback" (in this case 4).
--
DATA LIST LIST / case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.

SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 4.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.

LIST.

   
    case       id       in      out  episode
 
    1.00    11.00    13.00    17.00     1.00
    3.00    11.00    14.00    14.00     1.00
    5.00    11.00    17.00    22.00     1.00
    7.00    11.00    27.00    29.00     2.00
    2.00    12.00    14.00    15.00     3.00
    6.00    12.00    17.00    24.00     4.00
    4.00    13.00    15.00    22.00     5.00
 
 
Number of cases read:  7    Number of cases listed:  7
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: Finding and marking related cases

nessie
Thank's a lot.

Is there any way to find the number of combined  cases I shall put in the "lookback", or is there a syntax that can regulate this itself? I have a couple of hundred thousand singel cases in total and no idea how many combined cases I will end up with.
Is it possible to sort the constructed combined case numbers based on in and not id first?

Best regards
Lars N.

19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion] <[hidden email]>:

Something like the following?
Note you may need to change the number of cases in the "lookback" (in this case 4).
--
DATA LIST LIST / case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.

SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 4.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.

LIST.

   
    case       id       in      out  episode
 
    1.00    11.00    13.00    17.00     1.00
    3.00    11.00    14.00    14.00     1.00
    5.00    11.00    17.00    22.00     1.00
    7.00    11.00    27.00    29.00     2.00
    2.00    12.00    14.00    15.00     3.00
    6.00    12.00    17.00    24.00     4.00
    4.00    13.00    15.00    22.00     5.00
 
 
Number of cases read:  7    Number of cases listed:  7
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
To unsubscribe from Finding and marking related cases, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

Ruben Geert van den Berg
Dear Nessie,

You could use AGGREGATE for finding the "lookback" like so:

sort cases id.

aggregate outfile * mode addvariables
/presorted
/break id
/id_count = n.

descriptives id_count.
*Use max value as "lookback".

I thought you could use the syntax below to "automatically control the lookback" and cut down on redundant loops as well but it generates the error that [blah blah] the value passed into LAG must be a constant (over cases, that is) which is not the case here. So thus far I don't see a more efficient way than described above.

*Doesn't work.
IF ($CASENUM EQ 1) episode=1.
LOOP #lag = 1 to id_count.
+  IF (id=LAG(id,#lag)) AND RANGE(in,lag(in,#lag),lag(out,#lag)) episode=lag(episode).
END loop.
IF MISSING(episode) episode=LAG(episode) + 1.

Best,

Ruben
Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

nessie
Dear Ruben, thank's a lot!
I think I missunderstood the look back function to be a number of how many combined and singel cases I would end up with in total. If I understand you correct it's just the maximum number a singel id is repeated. That makes it very solvuable, as you did show. Thanks again 😊

Den 23. mai 2014 kl. 07:37 skrev "Ruben Geert van den Berg [via SPSSX Discussion]" <[hidden email]>:

Dear Nessie,

You could use AGGREGATE for finding the "lookback" like so:

sort cases id.

aggregate outfile * mode addvariables
/presorted
/break id
/id_count = n.

descriptives id_count.
*Use max value as "lookback".

I thought you could use the syntax below to "automatically control the lookback" and cut down on redundant loops as well but it generates the error that [blah blah] the value passed into LAG must be a constant (over cases, that is) which is not the case here. So thus far I don't see a more efficient way than described above.

*Doesn't work.
IF ($CASENUM EQ 1) episode=1.
LOOP #lag = 1 to id_count.
+  IF (id=LAG(id,#lag)) AND RANGE(in,lag(in,#lag),lag(out,#lag)) episode=lag(episode).
END loop.
IF MISSING(episode) episode=LAG(episode) + 1.

Best,

Ruben


If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726193.html
To unsubscribe from Finding and marking related cases, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

Rich Ulrich
In reply to this post by nessie
If I see the problem right, logically, you only need to look at one previous line. 

If it is the same episode, then you want to extend the testable OUT date
whenever the new line has a higher one.  Since the file is sorted by
IN, the previous IN is always okay.
     This looks like it should work -

SORT CASES BY id in out.
DO IF ($CASENUM EQ 1) 
+COMPUTE  episode=1.
+COMPUTE  hiout= out.
END IF.

DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
+COMPUTE episode=lag(episode).
+COMPUTE hiout= max(out, lag(hiout) ).
END IF.

DO IF MISSING(episode) .
+COMPUTE  episode=LAG(episode) + 1.
+COMPUTE  hiout= out.
END IF.

* That shows the logic explicitly.  Since temporary vars (#)  keep their
* values until changed, across cases, the code should work the same
* if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
* run faster than using lag(hiout).

--
Rich Ulrich




Date: Thu, 22 May 2014 13:43:25 -0700
From: [hidden email]
Subject: Re: Finding and marking related cases
To: [hidden email]

Thank's a lot.

Is there any way to find the number of combined  cases I shall put in the "lookback", or is there a syntax that can regulate this itself? I have a couple of hundred thousand singel cases in total and no idea how many combined cases I will end up with.
Is it possible to sort the constructed combined case numbers based on in and not id first?

Best regards
Lars N.

19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion] <[hidden email]>:

Something like the following?
Note you may need to change the number of cases in the "lookback" (in this case 4).
--
DATA LIST LIST / case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.

SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 4.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.

LIST.

   
    case       id       in      out  episode
 
    1.00    11.00    13.00    17.00     1.00
    3.00    11.00    14.00    14.00     1.00
    5.00    11.00    17.00    22.00     1.00
    7.00    11.00    27.00    29.00     2.00
    2.00    12.00    14.00    15.00     3.00
    6.00    12.00    17.00    24.00     4.00
    4.00    13.00    15.00    22.00     5.00
 
 
Number of cases read:  7    Number of cases listed:  7
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
To unsubscribe from Finding and marking related cases, click here.
NAML



View this message in context: Re: Finding and marking related cases
Sent from the SPSSX Discussion mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

nessie
Hi Rich
I tried you syntax, but got the following error message:

SORT CASES BY id in out.
DO IF ($CASENUM EQ 1)
+COMPUTE  episode=1.

Error # 4285 in column 2.  Text: COMPUTE
Incorrect variable name: either the name is more than 64 characters, or it is
not defined by a previous command.
Execution of this command stops.
+COMPUTE  hiout= out.
END IF.

Error # 4070.  Command name: END IF
The command does not follow an unclosed DO IF command.  Maybe the DO IF
command was not recognized because of an error.  Use the level-of-control
shown to the left of the SPSS Statistics commands to determine the range of
LOOPs and DO IFs.
Execution of this command stops.

DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
+COMPUTE episode=lag(episode).
+COMPUTE hiout= max(out, lag(hiout) ).
END IF.

DO IF MISSING(episode) .
+COMPUTE  episode=LAG(episode) + 1.
+COMPUTE  hiout= out.
END IF.

Best regards
Lars N.

23. mai 2014 kl. 09:00 skrev Rich Ulrich [via SPSSX Discussion] <[hidden email]>:

If I see the problem right, logically, you only need to look at one previous line.  

If it is the same episode, then you want to extend the testable OUT date 
whenever the new line has a higher one.  Since the file is sorted by
IN, the previous IN is always okay. 
     This looks like it should work -

SORT CASES BY id in out. 
DO IF ($CASENUM EQ 1)  
+COMPUTE  episode=1. 
+COMPUTE  hiout= out. 
END IF.

DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
+COMPUTE episode=lag(episode). 
+COMPUTE hiout= max(out, lag(hiout) ). 
END IF. 

DO IF MISSING(episode) .
+COMPUTE  episode=LAG(episode) + 1. 
+COMPUTE  hiout= out. 
END IF. 

* That shows the logic explicitly.  Since temporary vars (#)  keep their
* values until changed, across cases, the code should work the same
* if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
* run faster than using lag(hiout).

-- 
Rich Ulrich 




Date: Thu, 22 May 2014 13:43:25 -0700
From: <a href="x-msg://12/user/SendEmail.jtp?type=node&amp;node=5726195&amp;i=0" target="_top" rel="nofollow" link="external">[hidden email]
Subject: Re: Finding and marking related cases
To: <a href="x-msg://12/user/SendEmail.jtp?type=node&amp;node=5726195&amp;i=1" target="_top" rel="nofollow" link="external">[hidden email]

Thank's a lot.

Is there any way to find the number of combined  cases I shall put in the "lookback", or is there a syntax that can regulate this itself? I have a couple of hundred thousand singel cases in total and no idea how many combined cases I will end up with.
Is it possible to sort the constructed combined case numbers based on in and not id first?

Best regards
Lars N.

19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion] <[hidden email]>:

Something like the following? 
Note you may need to change the number of cases in the "lookback" (in this case 4). 
-- 
DATA LIST LIST / case id in out. 
BEGIN DATA. 
1, 11, 13, 17 
2, 12, 14, 15 
3, 11, 14, 14 
4, 13, 15, 22 
5, 11, 17, 22 
6, 12, 17, 24 
7, 11, 27, 29 
END DATA. 

SORT CASES BY id in out. 
IF ($CASENUM EQ 1) episode=1. 
DO REPEAT #=1 TO 4. 
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode). 
END REPEAT. 
IF MISSING(episode) episode=LAG(episode) + 1. 

LIST. 

    
    case       id       in      out  episode 
  
    1.00    11.00    13.00    17.00     1.00 
    3.00    11.00    14.00    14.00     1.00 
    5.00    11.00    17.00    22.00     1.00 
    7.00    11.00    27.00    29.00     2.00 
    2.00    12.00    14.00    15.00     3.00 
    6.00    12.00    17.00    24.00     4.00 
    4.00    13.00    15.00    22.00     5.00 
  
  
Number of cases read:  7    Number of cases listed:  7
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
To unsubscribe from Finding and marking related cases, <a href="https://" rel="nofollow" target="_blank">click here.
NAML



View this message in context: Re: Finding and marking related cases
Sent from the SPSSX Discussion mailing list archive at Nabble.com.



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726195.html
To unsubscribe from Finding and marking related cases, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

Ruben Geert van den Berg
I didn't look into the syntax but it should be

DO IF ($CASENUM EQ 1). /*end line with period!.

instead of

DO IF ($CASENUM EQ 1)

HTH,

Ruben
Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

David Marso
Administrator
In reply to this post by Rich Ulrich
Good catch Rich!
Here is a version using #scratch variables and a slightly different approach.
DATA LIST LIST / case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.
 
SORT CASES BY id in out.
DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
+  COMPUTE  episode=SUM(1,LAG(episode)).
+  COMPUTE  #hiout= out.
ELSE.
+  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
END IF.
COMPUTE #hiout= max(out, #hiout ).

Rich Ulrich wrote
If I see the problem right, logically, you only need to look at one previous line.  

If it is the same episode, then you want to extend the testable OUT date
whenever the new line has a higher one.  Since the file is sorted by
IN, the previous IN is always okay.
     This looks like it should work -

SORT CASES BY id in out.

DO IF ($CASENUM EQ 1)  
+COMPUTE  episode=1.

+COMPUTE  hiout= out.
END IF.

DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
+COMPUTE episode=lag(episode).

+COMPUTE hiout= max(out, lag(hiout) ).
END IF.

DO IF MISSING(episode) .
+COMPUTE  episode=LAG(episode) + 1.

+COMPUTE  hiout= out.
END IF.

* That shows the logic explicitly.  Since temporary vars (#)  keep their
* values until changed, across cases, the code should work the same
* if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
* run faster than using lag(hiout).

--
Rich Ulrich



Date: Thu, 22 May 2014 13:43:25 -0700
From: [hidden email]
Subject: Re: Finding and marking related cases
To: [hidden email]

Thank's a lot.
Is there any way to find the number of combined  cases I shall put in the "lookback", or is there a syntax that can regulate this itself? I have a couple of hundred thousand singel cases in total and no idea how many combined cases I will end up with.Is it possible to sort the constructed combined case numbers based on in and not id first?
Best regardsLars N.
19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion] <[hidden email]>:

        Something like the following?

Note you may need to change the number of cases in the "lookback" (in this case 4).

--

DATA LIST LIST / case id in out.

BEGIN DATA.

1, 11, 13, 17

2, 12, 14, 15

3, 11, 14, 14

4, 13, 15, 22

5, 11, 17, 22

6, 12, 17, 24

7, 11, 27, 29

END DATA.


SORT CASES BY id in out.

IF ($CASENUM EQ 1) episode=1.

DO REPEAT #=1 TO 4.

+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).

END REPEAT.

IF MISSING(episode) episode=LAG(episode) + 1.


LIST.


   

    case       id       in      out  episode

 

    1.00    11.00    13.00    17.00     1.00

    3.00    11.00    14.00    14.00     1.00

    5.00    11.00    17.00    22.00     1.00

    7.00    11.00    27.00    29.00     2.00

    2.00    12.00    14.00    15.00     3.00

    6.00    12.00    17.00    24.00     4.00

    4.00    13.00    15.00    22.00     5.00

 

 

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



       
                                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?"
                       
       

       

       
       
                If you reply to this email, your message will be added to the discussion below:
                http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
       
       

                To unsubscribe from Finding and marking related cases, click here.

                NAML
       







View this message in context: Re: Finding and marking related cases

Sent from the SPSSX Discussion mailing list archive at Nabble.com.
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: Finding and marking related cases

nessie
I'm picking up this old tread.
You helped me a lot in finding related cases and marking them with chronological case number.Now I have a new problem!
 
I want to make a new aggregated case containing some info from the first and some from the last related case.
E.g. "In" from the first related and "Out" from the last related case. Can you help me do this?
 
Best regards
Lars N.
2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <[hidden email]>:
Good catch Rich!
Here is a version using #scratch variables and a slightly different approach.
DATA LIST LIST / case id in out.
BEGIN DATA.
1, 11, 13, 17
2, 12, 14, 15
3, 11, 14, 14
4, 13, 15, 22
5, 11, 17, 22
6, 12, 17, 24
7, 11, 27, 29
END DATA.
 
SORT CASES BY id in out.
DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
+  COMPUTE  episode=SUM(1,LAG(episode)).
+  COMPUTE  #hiout= out.
ELSE.
+  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
END IF.
COMPUTE #hiout= max(out, #hiout ).

Rich Ulrich wrote
If I see the problem right, logically, you only need to look at one previous line.  

If it is the same episode, then you want to extend the testable OUT date
whenever the new line has a higher one.  Since the file is sorted by
IN, the previous IN is always okay.
     This looks like it should work -

SORT CASES BY id in out.

DO IF ($CASENUM EQ 1)  
+COMPUTE  episode=1.

+COMPUTE  hiout= out.
END IF.

DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
+COMPUTE episode=lag(episode).

+COMPUTE hiout= max(out, lag(hiout) ).
END IF.

DO IF MISSING(episode) .
+COMPUTE  episode=LAG(episode) + 1.

+COMPUTE  hiout= out.
END IF.

* That shows the logic explicitly.  Since temporary vars (#)  keep their
* values until changed, across cases, the code should work the same
* if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
* run faster than using lag(hiout).

--
Rich Ulrich



Date: Thu, 22 May 2014 13:43:25 -0700
From: [hidden email]
Subject: Re: Finding and marking related cases
To: [hidden email]

Thank's a lot.
Is there any way to find the number of combined  cases I shall put in the "lookback", or is there a syntax that can regulate this itself? I have a couple of hundred thousand singel cases in total and no idea how many combined cases I will end up with.Is it possible to sort the constructed combined case numbers based on in and not id first?
Best regardsLars N.
19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion] <[hidden email]>:

        Something like the following?

Note you may need to change the number of cases in the "lookback" (in this case 4).

--

DATA LIST LIST / case id in out.

BEGIN DATA.

1, 11, 13, 17

2, 12, 14, 15

3, 11, 14, 14

4, 13, 15, 22

5, 11, 17, 22

6, 12, 17, 24

7, 11, 27, 29

END DATA.


SORT CASES BY id in out.

IF ($CASENUM EQ 1) episode=1.

DO REPEAT #=1 TO 4.

+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).

END REPEAT.

IF MISSING(episode) episode=LAG(episode) + 1.


LIST.


   

    case       id       in      out  episode

 

    1.00    11.00    13.00    17.00     1.00

    3.00    11.00    14.00    14.00     1.00

    5.00    11.00    17.00    22.00     1.00

    7.00    11.00    27.00    29.00     2.00

    2.00    12.00    14.00    15.00     3.00

    6.00    12.00    17.00    24.00     4.00

    4.00    13.00    15.00    22.00     5.00

 

 

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



       
                                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?"
                       
       

       

       
       
                If you reply to this email, your message will be added to the discussion below:
                http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
       
       

                To unsubscribe from Finding and marking related cases, click here.

                NAML
       







View this message in context: Re: Finding and marking related cases

Sent from the SPSSX Discussion mailing list archive at Nabble.com.
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
To unsubscribe from Finding and marking related cases, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

David Marso
Administrator
See AGGREGATE in the FM.  There are FIRST and LAST functions.
--
AGGREGATE OUTFILE * MODE=ADDVARIABLES /BREAK.../f=FIRST(?)/l=LAST(?)..........

nessie wrote
I'm picking up this old tread.
You helped me a lot in finding related cases and marking them with
chronological case number.Now I have a new problem!

I want to make a new aggregated case containing some info from the first
and some from the last related case.
E.g. "In" from the first related and "Out" from the last related case. Can
you help me do this?

Best regards
Lars N.
2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <
[hidden email]>:

> Good catch Rich!
> Here is a version using #scratch variables and a slightly different
> approach.
> DATA LIST LIST / case id in out.
> BEGIN DATA.
> 1, 11, 13, 17
> 2, 12, 14, 15
> 3, 11, 14, 14
> 4, 13, 15, 22
> 5, 11, 17, 22
> 6, 12, 17, 24
> 7, 11, 27, 29
> END DATA.
>
> SORT CASES BY id in out.
> DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
> +  COMPUTE  episode=SUM(1,LAG(episode)).
> +  COMPUTE  #hiout= out.
> ELSE.
> +  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
> END IF.
> COMPUTE #hiout= max(out, #hiout ).
>
>  Rich Ulrich wrote
> If I see the problem right, logically, you only need to look at one
> previous line.
>
> If it is the same episode, then you want to extend the testable OUT date
> whenever the new line has a higher one.  Since the file is sorted by
> IN, the previous IN is always okay.
>      This looks like it should work -
>
> SORT CASES BY id in out.
>
> DO IF ($CASENUM EQ 1)
> +COMPUTE  episode=1.
>
> +COMPUTE  hiout= out.
> END IF.
>
> DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
> +COMPUTE episode=lag(episode).
>
> +COMPUTE hiout= max(out, lag(hiout) ).
> END IF.
>
> DO IF MISSING(episode) .
> +COMPUTE  episode=LAG(episode) + 1.
>
> +COMPUTE  hiout= out.
> END IF.
>
> * That shows the logic explicitly.  Since temporary vars (#)  keep their
> * values until changed, across cases, the code should work the same
> * if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
> * run faster than using lag(hiout).
>
> --
> Rich Ulrich
>
>
>
> Date: Thu, 22 May 2014 13:43:25 -0700
> From: [hidden email]
> <http://user/SendEmail.jtp?type=node&node=5726201&i=0>
> Subject: Re: Finding and marking related cases
> To: [hidden email] <http://user/SendEmail.jtp?type=node&node=5726201&i=1>
>
> Thank's a lot.
> Is there any way to find the number of combined  cases I shall put in the
> "lookback", or is there a syntax that can regulate this itself? I have a
> couple of hundred thousand singel cases in total and no idea how many
> combined cases I will end up with.Is it possible to sort the constructed
> combined case numbers based on in and not id first?
> Best regardsLars N.
>  19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion] <[hidden
> email]>:
>
>         Something like the following?
>
> Note you may need to change the number of cases in the "lookback" (in this
> case 4).
>
> --
>
> DATA LIST LIST / case id in out.
>
> BEGIN DATA.
>
> 1, 11, 13, 17
>
> 2, 12, 14, 15
>
> 3, 11, 14, 14
>
> 4, 13, 15, 22
>
> 5, 11, 17, 22
>
> 6, 12, 17, 24
>
> 7, 11, 27, 29
>
> END DATA.
>
>
> SORT CASES BY id in out.
>
> IF ($CASENUM EQ 1) episode=1.
>
> DO REPEAT #=1 TO 4.
>
> +  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#))
> episode=lag(episode).
>
> END REPEAT.
>
> IF MISSING(episode) episode=LAG(episode) + 1.
>
>
> LIST.
>
>
>
>
>     case       id       in      out  episode
>
>
>
>     1.00    11.00    13.00    17.00     1.00
>
>     3.00    11.00    14.00    14.00     1.00
>
>     5.00    11.00    17.00    22.00     1.00
>
>     7.00    11.00    27.00    29.00     2.00
>
>     2.00    12.00    14.00    15.00     3.00
>
>     6.00    12.00    17.00    24.00     4.00
>
>     4.00    13.00    15.00    22.00     5.00
>
>
>
>
>
> Number of cases read:  7    Number of cases listed:  7
>
>
>
>
>                                 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?"
>
>
>
>
>
>
>
>                 If you reply to this email, your message will be added to
> the discussion below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
>
>
>
>                 To unsubscribe from Finding and marking related cases,
> click here.
>
>                 NAML
>
>
>
>
>
>
>
>
> View this message in context: Re: Finding and marking related cases
>
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> 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?"
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
>  To unsubscribe from Finding and marking related cases, click here
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5726128&code=bGFyc25hZXNzQGdtYWlsLmNvbXw1NzI2MTI4fDM3MjU3NTE5>
> .
> NAML
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
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: Finding and marking related cases

nessie
Thanks David
That worked!
 
From the original question in this tread, I have made an episode variable linking concurrent admissions.
I have then sorted this in cronological order av given it a case number within the episode.
 
For "aggregated" episodes I now want to make a new case with aggregated data for all the same variables but pick some of the variables from the first and some from the last case. I can sort my episode variables according to casenumber and then try to aggregate with all the variables as break variables from either the first or the last case.
- Is this the best way to do it?
- What if I want to gather som data from on of the episodes in the middle? Is there an easy way to do this?
 
Best regards
Lars N.
 
 
2014-11-13 10:54 GMT+01:00 David Marso [via SPSSX Discussion] <[hidden email]>:
See AGGREGATE in the FM.  There are FIRST and LAST functions.
--
AGGREGATE OUTFILE * MODE=ADDVARIABLES /BREAK.../f=FIRST(?)/l=LAST(?)..........

nessie wrote
I'm picking up this old tread.
You helped me a lot in finding related cases and marking them with
chronological case number.Now I have a new problem!

I want to make a new aggregated case containing some info from the first
and some from the last related case.
E.g. "In" from the first related and "Out" from the last related case. Can
you help me do this?

Best regards
Lars N.
2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <
[hidden email]>:

> Good catch Rich!
> Here is a version using #scratch variables and a slightly different
> approach.
> DATA LIST LIST / case id in out.
> BEGIN DATA.
> 1, 11, 13, 17
> 2, 12, 14, 15
> 3, 11, 14, 14
> 4, 13, 15, 22
> 5, 11, 17, 22
> 6, 12, 17, 24
> 7, 11, 27, 29
> END DATA.
>
> SORT CASES BY id in out.
> DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
> +  COMPUTE  episode=SUM(1,LAG(episode)).
> +  COMPUTE  #hiout= out.
> ELSE.
> +  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
> END IF.
> COMPUTE #hiout= max(out, #hiout ).
>
>  Rich Ulrich wrote
> If I see the problem right, logically, you only need to look at one
> previous line.
>
> If it is the same episode, then you want to extend the testable OUT date
> whenever the new line has a higher one.  Since the file is sorted by
> IN, the previous IN is always okay.
>      This looks like it should work -
>
> SORT CASES BY id in out.
>
> DO IF ($CASENUM EQ 1)
> +COMPUTE  episode=1.
>
> +COMPUTE  hiout= out.
> END IF.
>
> DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
> +COMPUTE episode=lag(episode).
>
> +COMPUTE hiout= max(out, lag(hiout) ).
> END IF.
>
> DO IF MISSING(episode) .
> +COMPUTE  episode=LAG(episode) + 1.
>
> +COMPUTE  hiout= out.
> END IF.
>
> * That shows the logic explicitly.  Since temporary vars (#)  keep their
> * values until changed, across cases, the code should work the same
> * if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
> * run faster than using lag(hiout).
>
> --
> Rich Ulrich
>
>
>
> Date: Thu, 22 May 2014 13:43:25 -0700
> From: [hidden email]
> <http://user/SendEmail.jtp?type=node&node=5726201&i=0>
> Subject: Re: Finding and marking related cases
> To: [hidden email] <http://user/SendEmail.jtp?type=node&node=5726201&i=1>

>
> Thank's a lot.
> Is there any way to find the number of combined  cases I shall put in the
> "lookback", or is there a syntax that can regulate this itself? I have a
> couple of hundred thousand singel cases in total and no idea how many
> combined cases I will end up with.Is it possible to sort the constructed
> combined case numbers based on in and not id first?
> Best regardsLars N.
>  19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion] <[hidden
> email]>:
>
>         Something like the following?
>
> Note you may need to change the number of cases in the "lookback" (in this
> case 4).
>
> --
>
> DATA LIST LIST / case id in out.
>
> BEGIN DATA.
>
> 1, 11, 13, 17
>
> 2, 12, 14, 15
>
> 3, 11, 14, 14
>
> 4, 13, 15, 22
>
> 5, 11, 17, 22
>
> 6, 12, 17, 24
>
> 7, 11, 27, 29
>
> END DATA.
>
>
> SORT CASES BY id in out.
>
> IF ($CASENUM EQ 1) episode=1.
>
> DO REPEAT #=1 TO 4.
>
> +  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#))
> episode=lag(episode).
>
> END REPEAT.
>
> IF MISSING(episode) episode=LAG(episode) + 1.
>
>
> LIST.
>
>
>
>
>     case       id       in      out  episode
>
>
>
>     1.00    11.00    13.00    17.00     1.00
>
>     3.00    11.00    14.00    14.00     1.00
>
>     5.00    11.00    17.00    22.00     1.00
>
>     7.00    11.00    27.00    29.00     2.00
>
>     2.00    12.00    14.00    15.00     3.00
>
>     6.00    12.00    17.00    24.00     4.00
>
>     4.00    13.00    15.00    22.00     5.00
>
>
>
>
>
> Number of cases read:  7    Number of cases listed:  7
>
>
>
>
>                                 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?"
>
>
>
>
>
>
>
>                 If you reply to this email, your message will be added to
> the discussion below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
>
>
>
>                 To unsubscribe from Finding and marking related cases,
> click here.
>
>                 NAML
>
>
>
>
>
>
>
>
> View this message in context: Re: Finding and marking related cases
>
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> 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?"
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
>  To unsubscribe from Finding and marking related cases, click here
> < .
> NAML
> <
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727915.html
To unsubscribe from Finding and marking related cases, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

David Marso
Administrator
Lars,
  Please post a more illustrative data set with a before/after of how you want the final result to appear.
Meanwhile look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES commands.
HTH, David
==
nessie wrote
Thanks David
That worked!

From the original question in this tread, I have made an episode variable
linking concurrent admissions.
I have then sorted this in cronological order av given it a case number
within the episode.

For "aggregated" episodes I now want to make a new case with aggregated
data for all the same variables but pick some of the variables from the
first and some from the last case. I can sort my episode variables
according to casenumber and then try to aggregate with all the variables as
break variables from either the first or the last case.
- Is this the best way to do it?
- What if I want to gather som data from on of the episodes in the middle?
Is there an easy way to do this?

Best regards
Lars N.


2014-11-13 10:54 GMT+01:00 David Marso [via SPSSX Discussion] <
[hidden email]>:

> See AGGREGATE in the FM.  There are FIRST and LAST functions.
> --
> AGGREGATE OUTFILE * MODE=ADDVARIABLES
> /BREAK.../f=FIRST(?)/l=LAST(?)..........
>
>  nessie wrote
> I'm picking up this old tread.
> You helped me a lot in finding related cases and marking them with
> chronological case number.Now I have a new problem!
>
> I want to make a new aggregated case containing some info from the first
> and some from the last related case.
> E.g. "In" from the first related and "Out" from the last related case. Can
> you help me do this?
>
> Best regards
> Lars N.
> 2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <
> [hidden email] <http://user/SendEmail.jtp?type=node&node=5727915&i=0>>:
>
> > Good catch Rich!
> > Here is a version using #scratch variables and a slightly different
> > approach.
> > DATA LIST LIST / case id in out.
> > BEGIN DATA.
> > 1, 11, 13, 17
> > 2, 12, 14, 15
> > 3, 11, 14, 14
> > 4, 13, 15, 22
> > 5, 11, 17, 22
> > 6, 12, 17, 24
> > 7, 11, 27, 29
> > END DATA.
> >
> > SORT CASES BY id in out.
> > DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
> > +  COMPUTE  episode=SUM(1,LAG(episode)).
> > +  COMPUTE  #hiout= out.
> > ELSE.
> > +  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
> > END IF.
> > COMPUTE #hiout= max(out, #hiout ).
> >
> >  Rich Ulrich wrote
> > If I see the problem right, logically, you only need to look at one
> > previous line.
> >
> > If it is the same episode, then you want to extend the testable OUT date
> > whenever the new line has a higher one.  Since the file is sorted by
> > IN, the previous IN is always okay.
> >      This looks like it should work -
> >
> > SORT CASES BY id in out.
> >
> > DO IF ($CASENUM EQ 1)
> > +COMPUTE  episode=1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
> > +COMPUTE episode=lag(episode).
> >
> > +COMPUTE hiout= max(out, lag(hiout) ).
> > END IF.
> >
> > DO IF MISSING(episode) .
> > +COMPUTE  episode=LAG(episode) + 1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > * That shows the logic explicitly.  Since temporary vars (#)  keep their
> > * values until changed, across cases, the code should work the same
> > * if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
> > * run faster than using lag(hiout).
> >
> > --
> > Rich Ulrich
> >
> >
> >
> > Date: Thu, 22 May 2014 13:43:25 -0700
> > From: [hidden email]
> > <http://user/SendEmail.jtp?type=node&node=5726201&i=0>
> > Subject: Re: Finding and marking related cases
> > To: [hidden email] <
> http://user/SendEmail.jtp?type=node&node=5726201&i=1>
>
> >
> > Thank's a lot.
> > Is there any way to find the number of combined  cases I shall put in
> the
> > "lookback", or is there a syntax that can regulate this itself? I have a
> > couple of hundred thousand singel cases in total and no idea how many
> > combined cases I will end up with.Is it possible to sort the constructed
> > combined case numbers based on in and not id first?
> > Best regardsLars N.
> >  19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion]
> <[hidden
> > email]>:
> >
> >         Something like the following?
> >
> > Note you may need to change the number of cases in the "lookback" (in
> this
> > case 4).
> >
> > --
> >
> > DATA LIST LIST / case id in out.
> >
> > BEGIN DATA.
> >
> > 1, 11, 13, 17
> >
> > 2, 12, 14, 15
> >
> > 3, 11, 14, 14
> >
> > 4, 13, 15, 22
> >
> > 5, 11, 17, 22
> >
> > 6, 12, 17, 24
> >
> > 7, 11, 27, 29
> >
> > END DATA.
> >
> >
> > SORT CASES BY id in out.
> >
> > IF ($CASENUM EQ 1) episode=1.
> >
> > DO REPEAT #=1 TO 4.
> >
> > +  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#))
> > episode=lag(episode).
> >
> > END REPEAT.
> >
> > IF MISSING(episode) episode=LAG(episode) + 1.
> >
> >
> > LIST.
> >
> >
> >
> >
> >     case       id       in      out  episode
> >
> >
> >
> >     1.00    11.00    13.00    17.00     1.00
> >
> >     3.00    11.00    14.00    14.00     1.00
> >
> >     5.00    11.00    17.00    22.00     1.00
> >
> >     7.00    11.00    27.00    29.00     2.00
> >
> >     2.00    12.00    14.00    15.00     3.00
> >
> >     6.00    12.00    17.00    24.00     4.00
> >
> >     4.00    13.00    15.00    22.00     5.00
> >
> >
> >
> >
> >
> > Number of cases read:  7    Number of cases listed:  7
> >
> >
> >
> >
> >                                 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?"
> >
> >
> >
> >
> >
> >
> >
> >                 If you reply to this email, your message will be added
> to
> > the discussion below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
> >
> >
> >
> >                 To unsubscribe from Finding and marking related cases,
> > click here.
> >
> >                 NAML
> >
> >
> >
> >
> >
> >
> >
> >
> > View this message in context: Re: Finding and marking related cases
> >
> > Sent from the SPSSX Discussion mailing list archive at Nabble.com.
> >
> > 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?"
> >
> >
> > ------------------------------
> >  If you reply to this email, your message will be added to the
> discussion
> > below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
> >  To unsubscribe from Finding and marking related cases, click here
> > <
> http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5726128&code=bGFyc25hZXNzQGdtYWlsLmNvbXw1NzI2MTI4fDM3MjU3NTE5>
> > .
> > NAML
> > <
> http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml%3E>
> >
>
> 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?"
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727915.html
>  To unsubscribe from Finding and marking related cases, click here
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5726128&code=bGFyc25hZXNzQGdtYWlsLmNvbXw1NzI2MTI4fDM3MjU3NTE5>
> .
> NAML
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
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: Finding and marking related cases

nessie

Here is an example syntax. dia=diagnosis, c_level=care_level (IP=In-Patient, OP=Out-Patient), case=unique case_ID, id=person_ID, in=date_in, out=date_out
 
 DATA LIST LIST
/ dia (A2) c_level (A2) case id in out .
BEGIN DATA.
"A1" "IP" 1 11 13 17
"B1" "OP" 2 12 15 15
"A1" "OP" 3 11 14 14
"A2" "IP" 4 13 15 22
"B2" "IP" 5 11 17 22
"C1" "IP" 6 12 17 24
"B3" "IP" 7 11 27 29
"C4" "IP" 8 13 22 29
"D1" "IP" 9 12 24 26
"D2" "IP" 10 12 28 30
END DATA.
LIST.
SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 10.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.
LIST.
SORT CASES BY episode(A) in(A) out(A).
MATCH FILES
  /FILE=*
  /BY episode
  /FIRST=FirstCase
  /LAST=PrimaryLast.
DO IF (FirstCase).
COMPUTE  CaseNr=1-PrimaryLast.
ELSE.
COMPUTE  CaseNr=CaseNr+1.
END IF.
LEAVE  CaseNr.
FORMATS  CaseNr (f7).
MATCH FILES
  /FILE=*
  /DROP=PrimaryLast.
VALUE LABELS  FirstCase 0 'Duplicate Case' 1 'Primary Case' 2'Unique case'.
VARIABLE LEVEL  FirstCase (ORDINAL) /CaseNr (SCALE).
EXECUTE.
IF (CaseNr=0) FirstCase=2.
EXECUTE.
IF (FirstCase=2) CaseNr=1.
EXECUTE.
From this I want to keep all the uniqe cases but also make a new aggregatet case for all episodes containing "in" from the first case and "out" from the last, the "id", and "episode" variables, the last "Dia" variable, and the first "c_level" variable.
 
I also want to know e.g. how many different unique diagnosis within the same episode and if the "c_level" has been the same for all cases within one episode.
 
I will look up look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES, thanks for the tip.
 
Best regards
Lars
 
2014-11-13 14:18 GMT+01:00 David Marso [via SPSSX Discussion] <[hidden email]>:
Lars,
  Please post a more illustrative data set with a before/after of how you want the final result to appear.
Meanwhile look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES commands.
HTH, David
==
nessie wrote
Thanks David
That worked!

From the original question in this tread, I have made an episode variable
linking concurrent admissions.
I have then sorted this in cronological order av given it a case number
within the episode.

For "aggregated" episodes I now want to make a new case with aggregated
data for all the same variables but pick some of the variables from the
first and some from the last case. I can sort my episode variables
according to casenumber and then try to aggregate with all the variables as
break variables from either the first or the last case.
- Is this the best way to do it?
- What if I want to gather som data from on of the episodes in the middle?
Is there an easy way to do this?

Best regards
Lars N.


2014-11-13 10:54 GMT+01:00 David Marso [via SPSSX Discussion] <
[hidden email]>:

> See AGGREGATE in the FM.  There are FIRST and LAST functions.
> --
> AGGREGATE OUTFILE * MODE=ADDVARIABLES
> /BREAK.../f=FIRST(?)/l=LAST(?)..........
>
>  nessie wrote
> I'm picking up this old tread.
> You helped me a lot in finding related cases and marking them with
> chronological case number.Now I have a new problem!
>
> I want to make a new aggregated case containing some info from the first
> and some from the last related case.
> E.g. "In" from the first related and "Out" from the last related case. Can
> you help me do this?
>
> Best regards
> Lars N.
> 2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <
> [hidden email] <http://user/SendEmail.jtp?type=node&node=5727915&i=0>>:
>

> > Good catch Rich!
> > Here is a version using #scratch variables and a slightly different
> > approach.
> > DATA LIST LIST / case id in out.
> > BEGIN DATA.
> > 1, 11, 13, 17
> > 2, 12, 14, 15
> > 3, 11, 14, 14
> > 4, 13, 15, 22
> > 5, 11, 17, 22
> > 6, 12, 17, 24
> > 7, 11, 27, 29
> > END DATA.
> >
> > SORT CASES BY id in out.
> > DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
> > +  COMPUTE  episode=SUM(1,LAG(episode)).
> > +  COMPUTE  #hiout= out.
> > ELSE.
> > +  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
> > END IF.
> > COMPUTE #hiout= max(out, #hiout ).
> >
> >  Rich Ulrich wrote
> > If I see the problem right, logically, you only need to look at one
> > previous line.
> >
> > If it is the same episode, then you want to extend the testable OUT date
> > whenever the new line has a higher one.  Since the file is sorted by
> > IN, the previous IN is always okay.
> >      This looks like it should work -
> >
> > SORT CASES BY id in out.
> >
> > DO IF ($CASENUM EQ 1)
> > +COMPUTE  episode=1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
> > +COMPUTE episode=lag(episode).
> >
> > +COMPUTE hiout= max(out, lag(hiout) ).
> > END IF.
> >
> > DO IF MISSING(episode) .
> > +COMPUTE  episode=LAG(episode) + 1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > * That shows the logic explicitly.  Since temporary vars (#)  keep their
> > * values until changed, across cases, the code should work the same
> > * if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
> > * run faster than using lag(hiout).
> >
> > --
> > Rich Ulrich
> >
> >
> >
> > Date: Thu, 22 May 2014 13:43:25 -0700
> > From: [hidden email]
> > <http://user/SendEmail.jtp?type=node&node=5726201&i=0>
> > Subject: Re: Finding and marking related cases
> > To: [hidden email] <
> http://user/SendEmail.jtp?type=node&node=5726201&i=1>
>
> >
> > Thank's a lot.
> > Is there any way to find the number of combined  cases I shall put in
> the
> > "lookback", or is there a syntax that can regulate this itself? I have a
> > couple of hundred thousand singel cases in total and no idea how many
> > combined cases I will end up with.Is it possible to sort the constructed
> > combined case numbers based on in and not id first?
> > Best regardsLars N.
> >  19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion]
> <[hidden
> > email]>:
> >
> >         Something like the following?
> >
> > Note you may need to change the number of cases in the "lookback" (in
> this
> > case 4).
> >
> > --
> >
> > DATA LIST LIST / case id in out.
> >
> > BEGIN DATA.
> >
> > 1, 11, 13, 17
> >
> > 2, 12, 14, 15
> >
> > 3, 11, 14, 14
> >
> > 4, 13, 15, 22
> >
> > 5, 11, 17, 22
> >
> > 6, 12, 17, 24
> >
> > 7, 11, 27, 29
> >
> > END DATA.
> >
> >
> > SORT CASES BY id in out.
> >
> > IF ($CASENUM EQ 1) episode=1.
> >
> > DO REPEAT #=1 TO 4.
> >
> > +  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#))
> > episode=lag(episode).
> >
> > END REPEAT.
> >
> > IF MISSING(episode) episode=LAG(episode) + 1.
> >
> >
> > LIST.
> >
> >
> >
> >
> >     case       id       in      out  episode
> >
> >
> >
> >     1.00    11.00    13.00    17.00     1.00
> >
> >     3.00    11.00    14.00    14.00     1.00
> >
> >     5.00    11.00    17.00    22.00     1.00
> >
> >     7.00    11.00    27.00    29.00     2.00
> >
> >     2.00    12.00    14.00    15.00     3.00
> >
> >     6.00    12.00    17.00    24.00     4.00
> >
> >     4.00    13.00    15.00    22.00     5.00
> >
> >
> >
> >
> >
> > Number of cases read:  7    Number of cases listed:  7
> >
> >
> >
> >
> >                                 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?"
> >
> >
> >
> >
> >
> >
> >
> >                 If you reply to this email, your message will be added
> to
> > the discussion below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
> >
> >
> >
> >                 To unsubscribe from Finding and marking related cases,
> > click here.
> >
> >                 NAML
> >
> >
> >
> >
> >
> >
> >
> >
> > View this message in context: Re: Finding and marking related cases
> >
> > Sent from the SPSSX Discussion mailing list archive at Nabble.com.
> >
> > 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?"
> >
> >
> > ------------------------------
> >  If you reply to this email, your message will be added to the
> discussion
> > below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
> >  To unsubscribe from Finding and marking related cases, click here
> > <
>
> > .
> > NAML
> > <
>
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml%3E>

> >
>
> 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?"
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727915.html
>  To unsubscribe from Finding and marking related cases, click here
> < .
> NAML
> <
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727918.html
To unsubscribe from Finding and marking related cases, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

nessie
In reply to this post by David Marso
Sorry about the missing spaces, it probably doesn't matter, but I try again to make it more easy to read.
 
DATA LIST LIST
/ dia (A2) c_level (A2) case id in out .
BEGIN DATA.
"A1" "IP" 1 11 13 17
"B1" "OP" 2 12 15 15
"A1" "OP" 3 11 14 14
"A2" "IP" 4 13 15 22
"B2" "IP" 5 11 17 22
"C1" "IP" 6 12 17 24
"B3" "IP" 7 11 27 29
"C4" "IP" 8 13 22 29
"D1" "IP" 9 12 24 26
"D2" "IP" 10 12 28 30
END DATA.
LIST.
 
SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 10.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.
LIST.
 
SORT CASES BY episode(A) in(A) out(A).
MATCH FILES
  /FILE=*
  /BY episode
  /FIRST=FirstCase
  /LAST=PrimaryLast.
DO IF (FirstCase).
COMPUTE  CaseNr=1-PrimaryLast.
ELSE.
COMPUTE  CaseNr=CaseNr+1.
END IF.
LEAVE  CaseNr.
FORMATS  CaseNr (f7).
MATCH FILES
  /FILE=*
  /DROP=PrimaryLast.
VALUE LABELS  FirstCase 0 'Duplicate Case' 1 'Primary Case' 2'Unique case'.
VARIABLE LEVEL  FirstCase (ORDINAL) /CaseNr (SCALE).
EXECUTE.
 
IF (CaseNr=0) FirstCase=2.
EXECUTE.
IF (FirstCase=2) CaseNr=1.
EXECUTE.
2014-11-13 15:17 GMT+01:00 Lars E. Næss-Pleym <[hidden email]>:

Here is an example syntax. dia=diagnosis, c_level=care_level (IP=In-Patient, OP=Out-Patient), case=unique case_ID, id=person_ID, in=date_in, out=date_out
 
 DATA LIST LIST
/ dia (A2) c_level (A2) case id in out .
BEGIN DATA.
"A1" "IP" 1 11 13 17
"B1" "OP" 2 12 15 15
"A1" "OP" 3 11 14 14
"A2" "IP" 4 13 15 22
"B2" "IP" 5 11 17 22
"C1" "IP" 6 12 17 24
"B3" "IP" 7 11 27 29
"C4" "IP" 8 13 22 29
"D1" "IP" 9 12 24 26
"D2" "IP" 10 12 28 30
END DATA.
LIST.
SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 10.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.
LIST.
SORT CASES BY episode(A) in(A) out(A).
MATCH FILES
  /FILE=*
  /BY episode
  /FIRST=FirstCase
  /LAST=PrimaryLast.
DO IF (FirstCase).
COMPUTE  CaseNr=1-PrimaryLast.
ELSE.
COMPUTE  CaseNr=CaseNr+1.
END IF.
LEAVE  CaseNr.
FORMATS  CaseNr (f7).
MATCH FILES
  /FILE=*
  /DROP=PrimaryLast.
VALUE LABELS  FirstCase 0 'Duplicate Case' 1 'Primary Case' 2'Unique case'.
VARIABLE LEVEL  FirstCase (ORDINAL) /CaseNr (SCALE).
EXECUTE.
IF (CaseNr=0) FirstCase=2.
EXECUTE.
IF (FirstCase=2) CaseNr=1.
EXECUTE.
From this I want to keep all the uniqe cases but also make a new aggregatet case for all episodes containing "in" from the first case and "out" from the last, the "id", and "episode" variables, the last "Dia" variable, and the first "c_level" variable.
 
I also want to know e.g. how many different unique diagnosis within the same episode and if the "c_level" has been the same for all cases within one episode.
 
I will look up look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES, thanks for the tip.
 
Best regards
Lars
 
2014-11-13 14:18 GMT+01:00 David Marso [via SPSSX Discussion] <[hidden email]>:

Lars,
  Please post a more illustrative data set with a before/after of how you want the final result to appear.
Meanwhile look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES commands.
HTH, David
==
nessie wrote
Thanks David
That worked!

From the original question in this tread, I have made an episode variable
linking concurrent admissions.
I have then sorted this in cronological order av given it a case number
within the episode.

For "aggregated" episodes I now want to make a new case with aggregated
data for all the same variables but pick some of the variables from the
first and some from the last case. I can sort my episode variables
according to casenumber and then try to aggregate with all the variables as
break variables from either the first or the last case.
- Is this the best way to do it?
- What if I want to gather som data from on of the episodes in the middle?
Is there an easy way to do this?

Best regards
Lars N.


2014-11-13 10:54 GMT+01:00 David Marso [via SPSSX Discussion] <
[hidden email]>:

> See AGGREGATE in the FM.  There are FIRST and LAST functions.
> --
> AGGREGATE OUTFILE * MODE=ADDVARIABLES
> /BREAK.../f=FIRST(?)/l=LAST(?)..........
>
>  nessie wrote
> I'm picking up this old tread.
> You helped me a lot in finding related cases and marking them with
> chronological case number.Now I have a new problem!
>
> I want to make a new aggregated case containing some info from the first
> and some from the last related case.
> E.g. "In" from the first related and "Out" from the last related case. Can
> you help me do this?
>
> Best regards
> Lars N.
> 2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <
> [hidden email] <http://user/SendEmail.jtp?type=node&node=5727915&i=0>>:
>

> > Good catch Rich!
> > Here is a version using #scratch variables and a slightly different
> > approach.
> > DATA LIST LIST / case id in out.
> > BEGIN DATA.
> > 1, 11, 13, 17
> > 2, 12, 14, 15
> > 3, 11, 14, 14
> > 4, 13, 15, 22
> > 5, 11, 17, 22
> > 6, 12, 17, 24
> > 7, 11, 27, 29
> > END DATA.
> >
> > SORT CASES BY id in out.
> > DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
> > +  COMPUTE  episode=SUM(1,LAG(episode)).
> > +  COMPUTE  #hiout= out.
> > ELSE.
> > +  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
> > END IF.
> > COMPUTE #hiout= max(out, #hiout ).
> >
> >  Rich Ulrich wrote
> > If I see the problem right, logically, you only need to look at one
> > previous line.
> >
> > If it is the same episode, then you want to extend the testable OUT date
> > whenever the new line has a higher one.  Since the file is sorted by
> > IN, the previous IN is always okay.
> >      This looks like it should work -
> >
> > SORT CASES BY id in out.
> >
> > DO IF ($CASENUM EQ 1)
> > +COMPUTE  episode=1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
> > +COMPUTE episode=lag(episode).
> >
> > +COMPUTE hiout= max(out, lag(hiout) ).
> > END IF.
> >
> > DO IF MISSING(episode) .
> > +COMPUTE  episode=LAG(episode) + 1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > * That shows the logic explicitly.  Since temporary vars (#)  keep their
> > * values until changed, across cases, the code should work the same
> > * if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
> > * run faster than using lag(hiout).
> >
> > --
> > Rich Ulrich
> >
> >
> >
> > Date: Thu, 22 May 2014 13:43:25 -0700
> > From: [hidden email]
> > <http://user/SendEmail.jtp?type=node&node=5726201&i=0>
> > Subject: Re: Finding and marking related cases
> > To: [hidden email] <
> http://user/SendEmail.jtp?type=node&node=5726201&i=1>
>
> >
> > Thank's a lot.
> > Is there any way to find the number of combined  cases I shall put in
> the
> > "lookback", or is there a syntax that can regulate this itself? I have a
> > couple of hundred thousand singel cases in total and no idea how many
> > combined cases I will end up with.Is it possible to sort the constructed
> > combined case numbers based on in and not id first?
> > Best regardsLars N.
> >  19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion]
> <[hidden
> > email]>:
> >
> >         Something like the following?
> >
> > Note you may need to change the number of cases in the "lookback" (in
> this
> > case 4).
> >
> > --
> >
> > DATA LIST LIST / case id in out.
> >
> > BEGIN DATA.
> >
> > 1, 11, 13, 17
> >
> > 2, 12, 14, 15
> >
> > 3, 11, 14, 14
> >
> > 4, 13, 15, 22
> >
> > 5, 11, 17, 22
> >
> > 6, 12, 17, 24
> >
> > 7, 11, 27, 29
> >
> > END DATA.
> >
> >
> > SORT CASES BY id in out.
> >
> > IF ($CASENUM EQ 1) episode=1.
> >
> > DO REPEAT #=1 TO 4.
> >
> > +  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#))
> > episode=lag(episode).
> >
> > END REPEAT.
> >
> > IF MISSING(episode) episode=LAG(episode) + 1.
> >
> >
> > LIST.
> >
> >
> >
> >
> >     case       id       in      out  episode
> >
> >
> >
> >     1.00    11.00    13.00    17.00     1.00
> >
> >     3.00    11.00    14.00    14.00     1.00
> >
> >     5.00    11.00    17.00    22.00     1.00
> >
> >     7.00    11.00    27.00    29.00     2.00
> >
> >     2.00    12.00    14.00    15.00     3.00
> >
> >     6.00    12.00    17.00    24.00     4.00
> >
> >     4.00    13.00    15.00    22.00     5.00
> >
> >
> >
> >
> >
> > Number of cases read:  7    Number of cases listed:  7
> >
> >
> >
> >
> >                                 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?"
> >
> >
> >
> >
> >
> >
> >
> >                 If you reply to this email, your message will be added
> to
> > the discussion below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
> >
> >
> >
> >                 To unsubscribe from Finding and marking related cases,
> > click here.
> >
> >                 NAML
> >
> >
> >
> >
> >
> >
> >
> >
> > View this message in context: Re: Finding and marking related cases
> >
> > Sent from the SPSSX Discussion mailing list archive at Nabble.com.
> >
> > 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?"
> >
> >
> > ------------------------------
> >  If you reply to this email, your message will be added to the
> discussion
> > below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
> >  To unsubscribe from Finding and marking related cases, click here
> > <
>
> > .
> > NAML
> > <
>
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml%3E>

> >
>
> 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?"
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727915.html
>  To unsubscribe from Finding and marking related cases, click here
> < .
> NAML
> <
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727918.html
To unsubscribe from Finding and marking related cases, click here.
NAML


Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

nessie
In reply to this post by David Marso
I have worked my way through the basic aggregate functions and I'm starting to get the hang of it.
I have just one basic question - is it possible to count the number of different values a variable contains across the cases you aggregate and present all the different values in the aggregated sufix variables?
 
E.g. I have a patient who has been to several different hospital departments during one aggregated stay. For each case/episode the department variable returns a value. Lets say the has 10 different partial stays (cases) from 7 different departments wich I would like to aggregate. How can I count the number of different departments the patient has been to and present them in the aggregat variables (wich I would like to put at the end of each case/part of stay).
 
Best regards
Lars
 
2014-11-13 15:20 GMT+01:00 Lars E. Næss-Pleym <[hidden email]>:
Sorry about the missing spaces, it probably doesn't matter, but I try again to make it more easy to read.
 
DATA LIST LIST
/ dia (A2) c_level (A2) case id in out .
BEGIN DATA.
"A1" "IP" 1 11 13 17
"B1" "OP" 2 12 15 15
"A1" "OP" 3 11 14 14
"A2" "IP" 4 13 15 22
"B2" "IP" 5 11 17 22
"C1" "IP" 6 12 17 24
"B3" "IP" 7 11 27 29
"C4" "IP" 8 13 22 29
"D1" "IP" 9 12 24 26
"D2" "IP" 10 12 28 30
END DATA.
LIST.
 
SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 10.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.
LIST.
 
SORT CASES BY episode(A) in(A) out(A).
MATCH FILES
  /FILE=*
  /BY episode
  /FIRST=FirstCase
  /LAST=PrimaryLast.
DO IF (FirstCase).
COMPUTE  CaseNr=1-PrimaryLast.
ELSE.
COMPUTE  CaseNr=CaseNr+1.
END IF.
LEAVE  CaseNr.
FORMATS  CaseNr (f7).
MATCH FILES
  /FILE=*
  /DROP=PrimaryLast.
VALUE LABELS  FirstCase 0 'Duplicate Case' 1 'Primary Case' 2'Unique case'.
VARIABLE LEVEL  FirstCase (ORDINAL) /CaseNr (SCALE).
EXECUTE.
 
IF (CaseNr=0) FirstCase=2.
EXECUTE.
IF (FirstCase=2) CaseNr=1.
EXECUTE.
2014-11-13 15:17 GMT+01:00 Lars E. Næss-Pleym <[hidden email]>:

Here is an example syntax. dia=diagnosis, c_level=care_level (IP=In-Patient, OP=Out-Patient), case=unique case_ID, id=person_ID, in=date_in, out=date_out
 
 DATA LIST LIST
/ dia (A2) c_level (A2) case id in out .
BEGIN DATA.
"A1" "IP" 1 11 13 17
"B1" "OP" 2 12 15 15
"A1" "OP" 3 11 14 14
"A2" "IP" 4 13 15 22
"B2" "IP" 5 11 17 22
"C1" "IP" 6 12 17 24
"B3" "IP" 7 11 27 29
"C4" "IP" 8 13 22 29
"D1" "IP" 9 12 24 26
"D2" "IP" 10 12 28 30
END DATA.
LIST.
SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 10.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.
LIST.
SORT CASES BY episode(A) in(A) out(A).
MATCH FILES
  /FILE=*
  /BY episode
  /FIRST=FirstCase
  /LAST=PrimaryLast.
DO IF (FirstCase).
COMPUTE  CaseNr=1-PrimaryLast.
ELSE.
COMPUTE  CaseNr=CaseNr+1.
END IF.
LEAVE  CaseNr.
FORMATS  CaseNr (f7).
MATCH FILES
  /FILE=*
  /DROP=PrimaryLast.
VALUE LABELS  FirstCase 0 'Duplicate Case' 1 'Primary Case' 2'Unique case'.
VARIABLE LEVEL  FirstCase (ORDINAL) /CaseNr (SCALE).
EXECUTE.
IF (CaseNr=0) FirstCase=2.
EXECUTE.
IF (FirstCase=2) CaseNr=1.
EXECUTE.
From this I want to keep all the uniqe cases but also make a new aggregatet case for all episodes containing "in" from the first case and "out" from the last, the "id", and "episode" variables, the last "Dia" variable, and the first "c_level" variable.
 
I also want to know e.g. how many different unique diagnosis within the same episode and if the "c_level" has been the same for all cases within one episode.
 
I will look up look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES, thanks for the tip.
 
Best regards
Lars
 
2014-11-13 14:18 GMT+01:00 David Marso [via SPSSX Discussion] <[hidden email]>:

Lars,
  Please post a more illustrative data set with a before/after of how you want the final result to appear.
Meanwhile look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES commands.
HTH, David
==
nessie wrote
Thanks David
That worked!

From the original question in this tread, I have made an episode variable
linking concurrent admissions.
I have then sorted this in cronological order av given it a case number
within the episode.

For "aggregated" episodes I now want to make a new case with aggregated
data for all the same variables but pick some of the variables from the
first and some from the last case. I can sort my episode variables
according to casenumber and then try to aggregate with all the variables as
break variables from either the first or the last case.
- Is this the best way to do it?
- What if I want to gather som data from on of the episodes in the middle?
Is there an easy way to do this?

Best regards
Lars N.


2014-11-13 10:54 GMT+01:00 David Marso [via SPSSX Discussion] <
[hidden email]>:

> See AGGREGATE in the FM.  There are FIRST and LAST functions.
> --
> AGGREGATE OUTFILE * MODE=ADDVARIABLES
> /BREAK.../f=FIRST(?)/l=LAST(?)..........
>
>  nessie wrote
> I'm picking up this old tread.
> You helped me a lot in finding related cases and marking them with
> chronological case number.Now I have a new problem!
>
> I want to make a new aggregated case containing some info from the first
> and some from the last related case.
> E.g. "In" from the first related and "Out" from the last related case. Can
> you help me do this?
>
> Best regards
> Lars N.
> 2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <
> [hidden email] <http://user/SendEmail.jtp?type=node&node=5727915&i=0>>:
>

> > Good catch Rich!
> > Here is a version using #scratch variables and a slightly different
> > approach.
> > DATA LIST LIST / case id in out.
> > BEGIN DATA.
> > 1, 11, 13, 17
> > 2, 12, 14, 15
> > 3, 11, 14, 14
> > 4, 13, 15, 22
> > 5, 11, 17, 22
> > 6, 12, 17, 24
> > 7, 11, 27, 29
> > END DATA.
> >
> > SORT CASES BY id in out.
> > DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
> > +  COMPUTE  episode=SUM(1,LAG(episode)).
> > +  COMPUTE  #hiout= out.
> > ELSE.
> > +  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
> > END IF.
> > COMPUTE #hiout= max(out, #hiout ).
> >
> >  Rich Ulrich wrote
> > If I see the problem right, logically, you only need to look at one
> > previous line.
> >
> > If it is the same episode, then you want to extend the testable OUT date
> > whenever the new line has a higher one.  Since the file is sorted by
> > IN, the previous IN is always okay.
> >      This looks like it should work -
> >
> > SORT CASES BY id in out.
> >
> > DO IF ($CASENUM EQ 1)
> > +COMPUTE  episode=1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
> > +COMPUTE episode=lag(episode).
> >
> > +COMPUTE hiout= max(out, lag(hiout) ).
> > END IF.
> >
> > DO IF MISSING(episode) .
> > +COMPUTE  episode=LAG(episode) + 1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > * That shows the logic explicitly.  Since temporary vars (#)  keep their
> > * values until changed, across cases, the code should work the same
> > * if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
> > * run faster than using lag(hiout).
> >
> > --
> > Rich Ulrich
> >
> >
> >
> > Date: Thu, 22 May 2014 13:43:25 -0700
> > From: [hidden email]
> > <http://user/SendEmail.jtp?type=node&node=5726201&i=0>
> > Subject: Re: Finding and marking related cases
> > To: [hidden email] <
> http://user/SendEmail.jtp?type=node&node=5726201&i=1>
>
> >
> > Thank's a lot.
> > Is there any way to find the number of combined  cases I shall put in
> the
> > "lookback", or is there a syntax that can regulate this itself? I have a
> > couple of hundred thousand singel cases in total and no idea how many
> > combined cases I will end up with.Is it possible to sort the constructed
> > combined case numbers based on in and not id first?
> > Best regardsLars N.
> >  19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion]
> <[hidden
> > email]>:
> >
> >         Something like the following?
> >
> > Note you may need to change the number of cases in the "lookback" (in
> this
> > case 4).
> >
> > --
> >
> > DATA LIST LIST / case id in out.
> >
> > BEGIN DATA.
> >
> > 1, 11, 13, 17
> >
> > 2, 12, 14, 15
> >
> > 3, 11, 14, 14
> >
> > 4, 13, 15, 22
> >
> > 5, 11, 17, 22
> >
> > 6, 12, 17, 24
> >
> > 7, 11, 27, 29
> >
> > END DATA.
> >
> >
> > SORT CASES BY id in out.
> >
> > IF ($CASENUM EQ 1) episode=1.
> >
> > DO REPEAT #=1 TO 4.
> >
> > +  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#))
> > episode=lag(episode).
> >
> > END REPEAT.
> >
> > IF MISSING(episode) episode=LAG(episode) + 1.
> >
> >
> > LIST.
> >
> >
> >
> >
> >     case       id       in      out  episode
> >
> >
> >
> >     1.00    11.00    13.00    17.00     1.00
> >
> >     3.00    11.00    14.00    14.00     1.00
> >
> >     5.00    11.00    17.00    22.00     1.00
> >
> >     7.00    11.00    27.00    29.00     2.00
> >
> >     2.00    12.00    14.00    15.00     3.00
> >
> >     6.00    12.00    17.00    24.00     4.00
> >
> >     4.00    13.00    15.00    22.00     5.00
> >
> >
> >
> >
> >
> > Number of cases read:  7    Number of cases listed:  7
> >
> >
> >
> >
> >                                 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?"
> >
> >
> >
> >
> >
> >
> >
> >                 If you reply to this email, your message will be added
> to
> > the discussion below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
> >
> >
> >
> >                 To unsubscribe from Finding and marking related cases,
> > click here.
> >
> >                 NAML
> >
> >
> >
> >
> >
> >
> >
> >
> > View this message in context: Re: Finding and marking related cases
> >
> > Sent from the SPSSX Discussion mailing list archive at Nabble.com.
> >
> > 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?"
> >
> >
> > ------------------------------
> >  If you reply to this email, your message will be added to the
> discussion
> > below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
> >  To unsubscribe from Finding and marking related cases, click here
> > <
>
> > .
> > NAML
> > <
>
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml%3E>

> >
>
> 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?"
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727915.html
>  To unsubscribe from Finding and marking related cases, click here
> < .
> NAML
> <
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
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?"



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727918.html
To unsubscribe from Finding and marking related cases, click here.
NAML



Reply | Threaded
Open this post in threaded view
|

Re: Finding and marking related cases

David Marso
Administrator
Please for everyone's convenience, post an illustrative data-snap and the desired outcome!
I'm not going to bother to attempt to simulate something to test against! Your turn!
Off the cuff? CASESTOVARS?
---
nessie wrote
I have worked my way through the basic aggregate functions and I'm starting
to get the hang of it.
I have just one basic question - is it possible to count the number of
different values a variable contains across the cases you aggregate and
present all the different values in the aggregated sufix variables?

E.g. I have a patient who has been to several different hospital
departments during one aggregated stay. For each case/episode the
department variable returns a value. Lets say the has 10 different partial
stays (cases) from 7 different departments wich I would like to aggregate.
How can I count the number of different departments the patient has been to
and present them in the aggregat variables (wich I would like to put at the
end of each case/part of stay).

Best regards
Lars
<SNIP>
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: Finding and marking related cases

Maguin, Eugene
In reply to this post by nessie

Look at the aggregate function CIN. It returns a count of values between two endpoints.

Gene Maguin

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of nessie
Sent: Friday, November 21, 2014 7:30 AM
To: [hidden email]
Subject: Re: Finding and marking related cases

 

I have worked my way through the basic aggregate functions and I'm starting to get the hang of it.

I have just one basic question - is it possible to count the number of different values a variable contains across the cases you aggregate and present all the different values in the aggregated sufix variables?

 

E.g. I have a patient who has been to several different hospital departments during one aggregated stay. For each case/episode the department variable returns a value. Lets say the has 10 different partial stays (cases) from 7 different departments wich I would like to aggregate. How can I count the number of different departments the patient has been to and present them in the aggregat variables (wich I would like to put at the end of each case/part of stay).

 

Best regards

Lars

 

2014-11-13 15:20 GMT+01:00 Lars E. Næss-Pleym <[hidden email]>:

Sorry about the missing spaces, it probably doesn't matter, but I try again to make it more easy to read.

 

DATA LIST LIST
/ dia (A2) c_level (A2) case id in out .
BEGIN DATA.
"A1" "IP" 1 11 13 17
"B1" "OP" 2 12 15 15
"A1" "OP" 3 11 14 14
"A2" "IP" 4 13 15 22
"B2" "IP" 5 11 17 22
"C1" "IP" 6 12 17 24
"B3" "IP" 7 11 27 29
"C4" "IP" 8 13 22 29
"D1" "IP" 9 12 24 26
"D2" "IP" 10 12 28 30
END DATA.

LIST.

 

SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 10.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.

LIST.

 

SORT CASES BY episode(A) in(A) out(A).
MATCH FILES
  /FILE=*
  /BY episode
  /FIRST=FirstCase
  /LAST=PrimaryLast.
DO IF (FirstCase).
COMPUTE  CaseNr=1-PrimaryLast.
ELSE.
COMPUTE  CaseNr=CaseNr+1.
END IF.
LEAVE  CaseNr.
FORMATS  CaseNr (f7).
MATCH FILES
  /FILE=*
  /DROP=PrimaryLast.
VALUE LABELS  FirstCase 0 'Duplicate Case' 1 'Primary Case' 2'Unique case'.
VARIABLE LEVEL  FirstCase (ORDINAL) /CaseNr (SCALE).
EXECUTE.

 

IF (CaseNr=0) FirstCase=2.
EXECUTE.

IF (FirstCase=2) CaseNr=1.
EXECUTE.

2014-11-13 15:17 GMT+01:00 Lars E. Næss-Pleym <[hidden email]>:

 

Here is an example syntax. dia=diagnosis, c_level=care_level (IP=In-Patient, OP=Out-Patient), case=unique case_ID, id=person_ID, in=date_in, out=date_out

 

 DATA LIST LIST
/ dia (A2) c_level (A2) case id in out .
BEGIN DATA.
"A1" "IP" 1 11 13 17
"B1" "OP" 2 12 15 15
"A1" "OP" 3 11 14 14
"A2" "IP" 4 13 15 22
"B2" "IP" 5 11 17 22
"C1" "IP" 6 12 17 24
"B3" "IP" 7 11 27 29
"C4" "IP" 8 13 22 29
"D1" "IP" 9 12 24 26
"D2" "IP" 10 12 28 30
END DATA.

LIST.

SORT CASES BY id in out.
IF ($CASENUM EQ 1) episode=1.
DO REPEAT #=1 TO 10.
+  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#)) episode=lag(episode).
END REPEAT.
IF MISSING(episode) episode=LAG(episode) + 1.

LIST.

SORT CASES BY episode(A) in(A) out(A).
MATCH FILES
  /FILE=*
  /BY episode
  /FIRST=FirstCase
  /LAST=PrimaryLast.
DO IF (FirstCase).
COMPUTE  CaseNr=1-PrimaryLast.
ELSE.
COMPUTE  CaseNr=CaseNr+1.
END IF.
LEAVE  CaseNr.
FORMATS  CaseNr (f7).
MATCH FILES
  /FILE=*
  /DROP=PrimaryLast.
VALUE LABELS  FirstCase 0 'Duplicate Case' 1 'Primary Case' 2'Unique case'.
VARIABLE LEVEL  FirstCase (ORDINAL) /CaseNr (SCALE).
EXECUTE.

IF (CaseNr=0) FirstCase=2.
EXECUTE.

IF (FirstCase=2) CaseNr=1.
EXECUTE.

From this I want to keep all the uniqe cases but also make a new aggregatet case for all episodes containing "in" from the first case and "out" from the last, the "id", and "episode" variables, the last "Dia" variable, and the first "c_level" variable.

 

I also want to know e.g. how many different unique diagnosis within the same episode and if the "c_level" has been the same for all cases within one episode.

 

I will look up look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES, thanks for the tip.

 

Best regards

Lars
 

2014-11-13 14:18 GMT+01:00 David Marso [via SPSSX Discussion] <[hidden email]>:

 

Lars,
  Please post a more illustrative data set with a before/after of how you want the final result to appear.
Meanwhile look up AGGREGATE, RENAME VARIABLES, CASESTOVARS and MATCH FILES commands.
HTH, David
==

nessie wrote

Thanks David
That worked!

From the original question in this tread, I have made an episode variable
linking concurrent admissions.
I have then sorted this in cronological order av given it a case number
within the episode.

For "aggregated" episodes I now want to make a new case with aggregated
data for all the same variables but pick some of the variables from the
first and some from the last case. I can sort my episode variables
according to casenumber and then try to aggregate with all the variables as
break variables from either the first or the last case.
- Is this the best way to do it?
- What if I want to gather som data from on of the episodes in the middle?
Is there an easy way to do this?

Best regards
Lars N.


2014-11-13 10:54 GMT+01:00 David Marso [via SPSSX Discussion] <
[hidden email]>:


> See AGGREGATE in the FM.  There are FIRST and LAST functions.
> --
> AGGREGATE OUTFILE * MODE=ADDVARIABLES
> /BREAK.../f=FIRST(?)/l=LAST(?)..........
>
>  nessie wrote
> I'm picking up this old tread.
> You helped me a lot in finding related cases and marking them with
> chronological case number.Now I have a new problem!
>
> I want to make a new aggregated case containing some info from the first
> and some from the last related case.
> E.g. "In" from the first related and "Out" from the last related case. Can
> you help me do this?
>
> Best regards
> Lars N.
> 2014-05-23 12:39 GMT+02:00 David Marso [via SPSSX Discussion] <

> [hidden email] <http://user/SendEmail.jtp?type=node&node=5727915&i=0>>:

>


> > Good catch Rich!
> > Here is a version using #scratch variables and a slightly different
> > approach.
> > DATA LIST LIST / case id in out.
> > BEGIN DATA.
> > 1, 11, 13, 17
> > 2, 12, 14, 15
> > 3, 11, 14, 14
> > 4, 13, 15, 22
> > 5, 11, 17, 22
> > 6, 12, 17, 24
> > 7, 11, 27, 29
> > END DATA.
> >
> > SORT CASES BY id in out.
> > DO IF ($CASENUM EQ 1 OR id NE LAG(id) ).
> > +  COMPUTE  episode=SUM(1,LAG(episode)).
> > +  COMPUTE  #hiout= out.
> > ELSE.
> > +  COMPUTE episode=sum(lag(episode),NOT(range(in,lag(in),#hiout ))).
> > END IF.
> > COMPUTE #hiout= max(out, #hiout ).
> >
> >  Rich Ulrich wrote
> > If I see the problem right, logically, you only need to look at one
> > previous line.
> >
> > If it is the same episode, then you want to extend the testable OUT date
> > whenever the new line has a higher one.  Since the file is sorted by
> > IN, the previous IN is always okay.
> >      This looks like it should work -
> >
> > SORT CASES BY id in out.
> >
> > DO IF ($CASENUM EQ 1)
> > +COMPUTE  episode=1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > DO IF (id=LAG(id)) AND RANGE(in,lag(in),lag(hiout) ) .
> > +COMPUTE episode=lag(episode).
> >
> > +COMPUTE hiout= max(out, lag(hiout) ).
> > END IF.
> >
> > DO IF MISSING(episode) .
> > +COMPUTE  episode=LAG(episode) + 1.
> >
> > +COMPUTE  hiout= out.
> > END IF.
> >
> > * That shows the logic explicitly.  Since temporary vars (#)  keep their
> > * values until changed, across cases, the code should work the same
> > * if #hiout replaced both hiout and  lag(hiout). Conceivably, that might
> > * run faster than using lag(hiout).
> >
> > --
> > Rich Ulrich
> >
> >
> >
> > Date: Thu, 22 May 2014 13:43:25 -0700
> > From: [hidden email]
> > <http://user/SendEmail.jtp?type=node&node=5726201&i=0>
> > Subject: Re: Finding and marking related cases
> > To: [hidden email] <
> http://user/SendEmail.jtp?type=node&node=5726201&i=1>
>
> >
> > Thank's a lot.
> > Is there any way to find the number of combined  cases I shall put in
> the
> > "lookback", or is there a syntax that can regulate this itself? I have a
> > couple of hundred thousand singel cases in total and no idea how many
> > combined cases I will end up with.Is it possible to sort the constructed
> > combined case numbers based on in and not id first?
> > Best regardsLars N.
> >  19. mai 2014 kl. 18:22 skrev David Marso [via SPSSX Discussion]
> <[hidden
> > email]>:
> >
> >         Something like the following?
> >
> > Note you may need to change the number of cases in the "lookback" (in
> this
> > case 4).
> >
> > --
> >
> > DATA LIST LIST / case id in out.
> >
> > BEGIN DATA.
> >
> > 1, 11, 13, 17
> >
> > 2, 12, 14, 15
> >
> > 3, 11, 14, 14
> >
> > 4, 13, 15, 22
> >
> > 5, 11, 17, 22
> >
> > 6, 12, 17, 24
> >
> > 7, 11, 27, 29
> >
> > END DATA.
> >
> >
> > SORT CASES BY id in out.
> >
> > IF ($CASENUM EQ 1) episode=1.
> >
> > DO REPEAT #=1 TO 4.
> >
> > +  IF (id=LAG(id,#)) AND RANGE(in,lag(in,#),lag(out,#))
> > episode=lag(episode).
> >
> > END REPEAT.
> >
> > IF MISSING(episode) episode=LAG(episode) + 1.
> >
> >
> > LIST.
> >
> >
> >
> >
> >     case       id       in      out  episode
> >
> >
> >
> >     1.00    11.00    13.00    17.00     1.00
> >
> >     3.00    11.00    14.00    14.00     1.00
> >
> >     5.00    11.00    17.00    22.00     1.00
> >
> >     7.00    11.00    27.00    29.00     2.00
> >
> >     2.00    12.00    14.00    15.00     3.00
> >
> >     6.00    12.00    17.00    24.00     4.00
> >
> >     4.00    13.00    15.00    22.00     5.00
> >
> >
> >
> >
> >
> > Number of cases read:  7    Number of cases listed:  7
> >
> >
> >
> >
> >                                 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?"
> >
> >
> >
> >
> >
> >
> >
> >                 If you reply to this email, your message will be added
> to
> > the discussion below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726135.html
> >
> >
> >
> >                 To unsubscribe from Finding and marking related cases,
> > click here.
> >
> >                 NAML
> >
> >
> >
> >
> >
> >
> >
> >
> > View this message in context: Re: Finding and marking related cases
> >
> > Sent from the SPSSX Discussion mailing list archive at Nabble.com.
> >
> > 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?"
> >
> >
> > ------------------------------
> >  If you reply to this email, your message will be added to the
> discussion
> > below:
> >
> >
> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5726201.html
> >  To unsubscribe from Finding and marking related cases, click here
> > <
>
> > .
> > NAML
> > <
>
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>

> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml%3E>


> >
>
> 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?"
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>

> http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727915.html
>  To unsubscribe from Finding and marking related cases, click here
> < .
> NAML
> <
http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>

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?"

 


If you reply to this email, your message will be added to the discussion below:

http://spssx-discussion.1045642.n5.nabble.com/Finding-and-marking-related-cases-tp5726128p5727918.html

To unsubscribe from Finding and marking related cases, click here.
NAML

 

 

 


View this message in context: Re: Finding and marking related cases
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
12