|
I have a dataset that has multiple observations for each patients' visit to the hospital. Each observation is labeled 1-9 in a vaiable representing the 1st, 2nd, 3rd, etc visit. Each observation contains an admission and a discharge date. There are about 7000 patients with 13000 visits. all listes as a unique case observation.
I would like to find out the difference between the patient's discharge date from the first visit and the admission date of the second visit. And the difference between the patient's discharge dat from the 2nd visit and the admission date of the 3rd visit. Can I do this by some calcuation syntax or should I move the variable all onto 1 line running horizontally? Thanks! The set kind looks like this: Patient ID Visit Birthday Age Admission Discharge wdef9f8 1 1/31/1980 32 3/4/2009 3/6/2009 ikendr87 2 1/31/1980 32 7/15/2009 7/20/2009 dfggh34 3 1/31/1980 32 11/20/2009 11/30/2009 |
|
Administrator
|
Keep the data in long format!!!
See SORT CASES. See COMPUTE command and look at LAG function. Also see DO IF command to protect cross case contamination. Could also do this via CREATE command or SHIFT VALUES with SPLIT FILE in effect. This should get the juices flowing ;-) --
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?" |
|
Thats exactly what I was looking for. Thanks!
|
|
Okay, I am running into some trouble with this because I may have left out an important piece of information. I have matched these patients based on DOB, Gender, and Race. None have the same ID even though they are the same person. I cant rearrange the file or cases because I have them in order based on those matches and the date of services. I think this is slightly more complicated than I realized.
Is there a syntax that will allow me to create a unique ID for these folks that match? |
|
This post was updated on .
DOB Gender ID Visit# Admitdate DischDate
1/1/1900 1 1 1 3/5/2011 3/7/2011 1/1/1900 1 1 2 6/3/2011 6/7/2011 1/1/1900 1 1 3 1/2/2012 1/5/2012 4/20/1930 2 2 1 4/6/2005 4/8/2005 4/20/1930 2 2 2 6/23/2009 6/23/2009 7/5/1950 1 3 1 5/3/2006 5/6/2006 7/5/1950 1 3 2 4/5/2007 4/15/2007 I just want to elaborate a bit further for clarification. I was reading about creating ID's based on index numbers for groups. I found a way to do it, but I need to be able to actually do this in the reverse order. I have the Index variable (Visit #) Each visit is numbered. Right now for this example I created the ID variable that creates the same ID for each person. I need to be able to do that with a code, and not by hand. I have 46,000 visits! I want to tell SPSS that each time it sees a 1, it needs to create a number for that "set", each 1 would be the beginning of a new patient. |
|
Administrator
|
There are many ways to do this.
Using just your visit variable for simplicity. data list free/ visit. begin data 1 2 1 2 3 1 2 1 2 1 2 1 2 end data. compute #=SUM(#,visit EQ 1). COMPUTE SET=#. LIST. VISIT SET 1.00 1.00 2.00 1.00 1.00 2.00 2.00 2.00 3.00 2.00 1.00 3.00 2.00 3.00 1.00 4.00 2.00 4.00 1.00 5.00 2.00 5.00 1.00 6.00 2.00 6.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?" |
|
In reply to this post by abrea.johnson
It’s not clear what your data look like, but if all cases are in their own row, andyou want consecutive IDs try: Compute id = $casenum. This takes the row number for each case and inserts it as a new variable appended to the end of the file. You can move it to the top of the file by holding the left key down over the row number and dragging it. If there is more than one row of data for each case, someone else on the list will have a solution. John F Hall (Mr) [retired academic survey researcher] Email: [hidden email] Website: www.surveyresearch.weebly.com John F Hall (Mr) [retired academic survey researcher] Email: [hidden email] Website: www.surveyresearch.weebly.com -----Original Message----- Okay, I am running into some trouble with this because I may have left out an important piece of information. I have matched these patients based on DOB, Gender, and Race. None have the same ID even though they are the same person. I cant rearrange the file or cases because I have them in order based on those matches and the date of services. I think this is slightly more complicated than I realized. Is there a syntax that will allow me to create a unique ID for these folks that match? -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Calculate-or-move-variables-tp5717328p5717422.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
Administrator
|
In reply to this post by David Marso
For SPSS newbies who may not have encountered them yet, that # in David's solution is a "scratch variable". Here's what the FM says about scratch variables.
Scratch Variables You can use scratch variables to facilitate operations in transformation blocks and input programs. * To create a scratch variable, specify a variable name that begins with the # character—for example, #ID . Scratch variables can be either numeric or string. * Scratch variables are initialized to 0 for numeric variables or blank for string variables. * Scratch variables cannot be used in procedures and cannot be saved in a data file (but they can be written to an external text file with PRINT or WRITE). * Scratch variables cannot be assigned missing values, variable labels, or value labels. * Scratch variables can be created between procedures but are always discarded as the next procedure begins. * Scratch variables are discarded once a TEMPORARY command is specified. * The keyword TO cannot refer to scratch variables and permanent variables at the same time. * Scratch variables cannot be specified on a WEIGHT command. * Scratch variable cannot be specified on the LEAVE command. * Scratch variables are not reinitialized when a new case is read. Their values are always carried across cases. (So using a scratch variable can be essentially equivalent to using the LEAVEcommand.) The two bullet points I highlighted are important for David's syntax. Regular numeric variables are initialized to SYSMIS, not 0. HTH.
--
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/). |
|
This post was updated on .
In reply to this post by David Marso
David's suggestion worked. Everyone has a unique ID and each visit has a unique ID. Now on to the next step in calculating the difference between visits.......
|
|
In reply to this post by abrea.johnson
Ok, I cant get it to calculate the difference of the date in different columns or move the variables. I even just put in a simple lag syntax and it errors about loops and stuff. Ahh! Im going nuts here.
|
|
Administrator
|
<clue stick> Come on now! Get with the program!!! This is not twitter and you are not limited to 100 characters. Describe your problem with a certain amount of detail and don't be lazy about it!!</clue stick>
Post what you want it to look like and your current failed syntax. ERROR MESSAGES TOO IF ANY! We are not going to try to guess what you are doing or what you want!
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?" |
| Free forum by Nabble | Edit this page |
