Administrator
|
eg:
DATA LIST FREE / ID session x. BEGIN DATA 1 1 1 1 1 1 1 1 2 1 2 1 1 2 2 1 2 3 2 1 1 2 1 1 2 1 1 2 1 2 2 2 1 2 2 2 2 3 4 2 3 5 2 3 5 END DATA. AGGREGATE OUTFILE * / BREAK ID session x/ Count=N. AGGREGATE OUTFILE * MODE ADDVARIABLES / BREAK ID Session /N_X=N. CASESTOVARS ID=ID session/FIXED=N_x/DROP Count. LIST. ID session N_X x.1 x.2 x.3 1.00 1.00 2 1.00 2.00 . 1.00 2.00 3 1.00 2.00 3.00 2.00 1.00 2 1.00 2.00 . 2.00 2.00 2 1.00 2.00 . 2.00 3.00 2 4.00 5.00 . Number of cases read: 5 Number of cases listed: 5
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?" |
In reply to this post by Maguin, Eugene
Sorry for my very late reply and for not providing example data when I posted my question. I fell bad! Thank's to both of you for two different but excellent solutions. Espacially thank's to you David for taking time to make and provide am illustrative example. I have a new and different problem: I have a big number of hospital admissions. Some of them are special and draines a lot of resources and I want to mark all the other admissions within the time-frame of these admissions to check if they are influenced in a negative way. I modified your data David, to give an example. The special cases are marked with the value 1 for variable x. I want to make a new variable that markes all the cases that overlaps with the in/out time of these special cases. Here ID 3 and ID 8 are special cases, and I want to mark case; 2, 4 and 9. Best regards Lars DATA LIST FREE / ID in out x. BEGIN DATA 1 1 2 0 2 3 3 0 3 3 4 1 4 4 5 0 5 6 8 0 7 7 12 0 8 13 13 1 9 13 14 0 END DATA. This gives these data: ID in out x 1,00 1,00 2,00 ,00 2,00 3,00 3,00 ,00 3,00 3,00 4,00 1,00 4,00 4,00 5,00 ,00 5,00 6,00 8,00 ,00 7,00 7,00 12,00 ,00 8,00 13,00 13,00 1,00 9,00 13,00 14,00 ,00
2014-11-24 16:08 GMT+01:00 Maguin, Eugene [via SPSSX Discussion] <[hidden email]>:
|
Administrator
|
Look up SHIFT VALUES (alternatively use the CREATE command).
There is also a RANGE function in COMPUTE. --
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?" |
I have tried to solve this myself, but I can get it right.
I've used this example data: DATA LIST FREE / ID in out x. BEGIN DATA 1 1 2 0 2 3 3 0 3 3 4 1 4 4 5 0 5 6 8 0 6 7 9 0 7 7 12 0 8 13 13 1 9 13 14 0 10 14 16 0 END DATA. id is case id in is a fictive date/time equivalent out is a fictive date/time equivalent x is a marker (0=ordinary case, 1=special case) To sum up, I want to mark all cases which overlaps the in/out-span of the x=1 cases. I have tried to experiment with the lag and lead functions in SHIFT VALUES (thank’s for the tip David), but I haven’t come up with a working solution. Does anyone have any other tips or tricks to help me solve this problem? Best regards Lars
|
Administrator
|
It would be interesting to see what you tried.
Here is what I was trying to direct you toward: If next case is X then FLAG: If the 'out' of current case is between the 'in' and 'out' of this next case. If previous case is X FLAG if the 'in' of current case is between 'in' and 'out' of previous case. This can be concisely coded as a 'vector product' of the ranges and the 'xflags'. DATA LIST FREE / ID in out x. BEGIN DATA 1 1 2 0 2 3 3 0 3 3 4 1 4 4 5 0 5 6 8 0 6 7 9 0 7 7 12 0 8 13 13 1 9 13 14 0 10 14 16 0 END DATA. CREATE inlead=LEAD(in,1)/outlead=LEAD(out,1)/xlead=LEAD(x,1). COMPUTE flagged=SUM(RANGE(out,inlead,outlead) * xlead, RANGE(in,LAG(in),LAG(out))*LAG(x)). LIST.
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?" |
Administrator
|
In reply to this post by nessie
I had to go look at one of your earlier posts to try to understand what you want. The following is a (very) rough first draft, but I think it accomplishes what you are asking for. Notice the use of the RANGE function.
NEW FILE. DATASET CLOSE all. DATA LIST FREE / ID in out x. BEGIN DATA 1 1 2 0 2 3 3 0 3 3 4 1 4 4 5 0 5 6 8 0 6 7 9 0 7 7 12 0 8 13 13 1 9 13 14 0 10 14 16 0 END DATA. DATASET NAME Original. DATASET COPY Copy. DATASET ACTIVATE Copy. SELECT IF x EQ 1. LIST. VARSTOCASES /ID=id /MAKE InOut FROM in out /INDEX=Index1(2) /DROP=ID x /NULL=KEEP. SORT CASES BY id Index1. CASESTOVARS /INDEX=id Index1 /GROUPBY=VARIABLE /SEPARATOR="". COMPUTE @junk1 = 1. EXECUTE. DATASET ACTIVATE Original. COMPUTE @junk1 = 1. EXECUTE. MATCH FILES FILE = * / TABLE = "Copy" / BY @junk1. EXECUTE. DATASET NAME Final. DATASET ACTIVATE Final. DATASET CLOSE all. COMPUTE @junk2 = 1. COMPUTE FLAG = 0. DO REPEAT I = InOut11 InOut21 / O = InOut12 InOut22. - IF not Flag Flag = NOT x and (RANGE(in,I,O) OR RANGE(out,I,O)). END REPEAT. EXECUTE. DELETE VARIABLES @junk1 to @junk2. FORMATS Flag (F1). LIST. OUTPUT: ID in out x FLAG 1.00 1.00 2.00 .00 0 2.00 3.00 3.00 .00 1 3.00 3.00 4.00 1.00 0 4.00 4.00 5.00 .00 1 5.00 6.00 8.00 .00 0 6.00 7.00 9.00 .00 0 7.00 7.00 12.00 .00 0 8.00 13.00 13.00 1.00 0 9.00 13.00 14.00 .00 1 10.00 14.00 16.00 .00 0
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
This post was updated on .
In reply to this post by David Marso
<Addendum:>
Perhaps for logical clarity substitute + COMPUTE flagged=MAX(flagged,RANGE(#in,in,out) | RANGE(#out,in,out)). rather than the existing SUM function in the MACRO. That way it returns 0/1 rather than {0:4} </Addendum> Here is a conceptually simpler approach which has the advantage of also flagging cases where there are more than a single qualifying overlap. If this seems mysterious the look up SCRATCH variables in the FM and learn to love them. The macro (DEFINE !ENDDEFINE) is simply to avoid redundant code. DATA LIST FREE / ID in out x. BEGIN DATA 1 1 2 0 2 3 3 0 2.1 3 3.5 0 3 3 4 1 4 4 5 0 5 6 8 0 6 7 9 0 7 7 12 0 8 13 13 1 8.1 13 13.1 0 9 13 13.2 0 9.1 13 13.3 0 9.2 13 13.5 0 9.3 13 14 0 10 14 16 0 END DATA. DEFINE flag() DO IF x. + COMPUTE #in = in. + COMPUTE #out=out. ELSE. + COMPUTE flagged=SUM(flagged,RANGE(#in,in,out),RANGE(#out,in,out)). END IF. !ENDDEFINE. COMPUTE @order=$CASENUM. SORT CASES BY in (A) out (A). flag. SORT CASES BY out (D) in (D). flag. SORT CASES BY @order. LIST. ID in out x @order flagged 1.00 1.00 2.00 .00 1.00 .00 2.00 3.00 3.00 .00 2.00 1.00 2.00 3.00 3.50 .00 3.00 1.00 3.00 3.00 4.00 1.00 4.00 . 4.00 4.00 5.00 .00 5.00 1.00 5.00 6.00 8.00 .00 6.00 .00 6.00 7.00 9.00 .00 7.00 .00 7.00 7.00 12.00 .00 8.00 .00 8.00 13.00 13.00 1.00 9.00 . 8.00 13.00 13.10 .00 10.00 2.00 9.00 13.00 13.20 .00 11.00 2.00 9.00 13.00 13.30 .00 12.00 2.00 9.00 13.00 13.50 .00 13.00 2.00 9.00 13.00 14.00 .00 14.00 2.00 10.00 14.00 16.00 .00 15.00 .00
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?" |
Administrator
|
Ahem! Please disregard the Rubish* method I posted earlier. David's solution is far better.
* Re the meaning of "Rubish", please see http://www.rubegoldberg.com/. ;-)
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
Doh:
Also disregard my first draft 2 liner using the CREATE and complicated logical involving LEAD and LAG. My first version only covers 1. In principle clean for 1 but very messy if one has several possible overlapping cases. The #scratch variable version is far more general and elegant (since it covers all possible overlaps) and it doesn't require much cogitation to understand. Included here in it's latest incarnation. ---- DEFINE flag(!POS !CMDEND !DEFAULT('A D') ) COMPUTE @order=$CASENUM. !DO !I !IN (!1) SORT CASES BY in (!I) out (!I). DO IF x. + COMPUTE #in = in. + COMPUTE #out=out. ELSE. + COMPUTE flagged=MAX(flagged,RANGE(#in,in,out) | RANGE(#out,in,out)). END IF. !DOEND. SORT CASES BY @order. DELETE VARIABLES @order. !ENDDEFINE. DATA LIST FREE / ID in out x. BEGIN DATA 1 1 2 0 2 3 3 0 2.1 3 3.5 0 3 3 4 1 4 4 5 0 5 6 8 0 6 7 9 0 7 7 12 0 8 13 14 1 8.1 13 13.1 0 9 13 13.2 0 9.1 13 13.3 0 9.2 13 13.5 0 9.3 13 14 0 10 15 16 0 END DATA. flag. LIST.
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?" |
Thank's alot. You guys are fantastic. I will look into this at work tomorrow and give you a real feed back. Best regards
|
In reply to this post by Bruce Weaver
Dear David and Bruce This is so simple and exactly what I was trying to acchive. Works like a charm. I did some basic attempts myself making two new dummy variables for in/out with values only for det marked x=1 cases and then use lag to give this value to the next case until a new x=1 case appeared. I then check each case to se if it's real in/out was within the dummy in/out. This of course would only give information from presceding cases, and I had to make a new similar variable for lead check and integrate the results and everything got very complex. The logic of this was to complex for my simple mind. I am trying to get the hang of Shift values, RANGE, #scratch, macros etc. but it's still new to me and I could never achived this elegant solution on my own. Thank you very much the both of you. Now I can mark our patients to se if e.g. a simlutanious trauma in the E.D. have any influence on our general care taking. Thanks again. Best regards Lars 2014-12-16 19:06 GMT+01:00 Bruce Weaver [via SPSSX Discussion] <[hidden email]>: Ahem! Please disregard the Rubish* method I posted earlier. David's solution is far better. |
Free forum by Nabble | Edit this page |