Issue: How do I duplicate cases with syntax?
I am currently working with a data set from a behavioral health treatment center. At this treatment center, the administration conducts quarterly surveys regarding the status of the clients. The treatment center has 2 different programs; a residential and an outpatient. This survey is then entered into a data set. The data set has a string variable indicating the type of record of each survey administration. The variable is coded as A-admit, Q-quarter, D-discharge, and T-transfer. The transfer (T) is what is currently causing some issues. When someone receives a T, that means they have transferred from the residential to the outpatient. I want to take that T and create (duplicate) 2 additional records (cases), so the T becomes a residential discharge (DR) and a outpatient admit (AO). Below is a sample of the data. ID Number RecType PrgmType Var1 Var2 Var3 001 A 1 20 10 15 001 Q 1 20 10 15 001 Q 1 15 10 0 001 T 1 10 5 0 001 Q 2 5 5 0 001 D 2 5 0 0 Values Rectype-String PrgmType-numeric Var1-3-numeric A-Admit 1=residential =scores on survey items Q-Quarter 2=outpatient T-Transfer D-Discharge Thanks for your help with this issue. --------------------------------- Food fight? Enjoy some healthy debate in the Yahoo! Answers Food & Drink Q&A. |
At 02:50 PM 2/23/2007, Cody Chipp wrote:
>Issue: How do I duplicate cases with syntax? > >At [a] treatment center, the administration conducts quarterly surveys >regarding the status of the clients. The treatment center has 2 >different programs; a residential and an outpatient. The [resulting] >data set has a string variable indicating the type of record of each >survey administration. The variable is coded as A-admit, Q-quarter, >D-discharge, and T-transfer. A T that means they have transferred from >the residential to the outpatient. I want to take that T and create >(duplicate) 2 additional records (cases), so the T becomes a >residential discharge (DR) and a outpatient admit (AO). The way you write multiple cases from one in SPSS is using XSAVE within a LOOP. (VARSTOCASES is the other way, but I don't think it will serve your turn.) To replace each 'T' record with one 'DR' and one 'AO' record, try this. It's SPSS 14 draft output: * ............................................... . * "Below is a sample of the data." . LIST. List |-----------------------------|---------------------------| |Output Created |23-FEB-2007 20:59:16 | |-----------------------------|---------------------------| ID_Numbr RecType PgrmType Var1 Var2 Var3 1 A 1 20 10 15 1 Q 1 20 10 15 1 Q 1 15 10 0 1 T 1 10 5 0 1 Q 2 5 5 0 1 D 2 5 0 0 Number of cases read: 6 Number of cases listed: 6 STRING #InptType (A2). COMPUTE #InptType = RecType. LOOP #PASS = 1 TO 3. . COMPUTE #WriteIt = 0. . DO IF #Pass EQ 1 /* Straight output */. . IF #InptType NE 'T' #WriteIt = 1. . ELSE IF #Pass EQ 2 /* T -> DR */. . DO IF #InptType EQ 'T'. . COMPUTE RecType = 'DR'. . COMPUTE #WriteIt = 1. . END IF. . ELSE IF #Pass EQ 3 /* T -> AO */. . DO IF #InptType EQ 'T'. . COMPUTE RecType = 'AO'. . COMPUTE #WriteIt = 1. . END IF. . END IF. . DO IF #WriteIt EQ 1. . XSAVE OUTFILE=Expand. . END IF. END LOOP. EXECUTE. GET FILE=Expand. LIST. List |-----------------------------|---------------------------| |Output Created |23-FEB-2007 20:59:18 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2007-02-23 Chipp - How do a duplicate cases with syntax - EXPAND.SAV ID_Numbr RecType PgrmType Var1 Var2 Var3 1 A 1 20 10 15 1 Q 1 20 10 15 1 Q 1 15 10 0 1 DR 1 10 5 0 1 AO 1 10 5 0 1 Q 2 5 5 0 1 D 2 5 0 0 Number of cases read: 7 Number of cases listed: 7 =================== APPENDIX: Text data =================== * Variable values * Rectype-String PrgmType-numeric Var1-3-numeric . * A-Admit 1=residential =scores on survey items . * Q-Quarter 2=outpatient . * T-Transfer . * D-Discharge . DATA LIST LIST SKIP=1 /ID_Numbr (N3) RecType(A2) PgrmType(F2) Var1 Var2 Var3 (3F3). BEGIN DATA ID Number RecType PrgmType Var1 Var2 Var3 001 A 1 20 10 15 001 Q 1 20 10 15 001 Q 1 15 10 0 001 T 1 10 5 0 001 Q 2 5 5 0 001 D 2 5 0 0 END DATA. |
In reply to this post by Cody Chipp
Hi Cody.
Try this syntax (the DEL VAR command works only if you are using Version 12 or later but it is used to clean the new file) RECODE RecType ('T'=3) (ELSE=1) INTO nrec . LOOP I = 1 to nrec. XSAVE OUTFILE='C:\Clientes\cody.sav'/DROP= nrec. END LOOP. GET FILE='C:\Clientes\cody.sav'. DO IF I = 2. COMPUTE RecType = 'DR'. ELSE IF I = 3. COMPUTE RecType = 'AO'. END IF. EXECUTE. DEL VAR I. Regards, George ----- Original Message ----- From: "Cody Chipp" <[hidden email]> To: <[hidden email]> Sent: Friday, February 23, 2007 7:50 PM Subject: How do a duplicate cases with syntax? > Issue: How do I duplicate cases with syntax? > > I am currently working with a data set from a behavioral health treatment center. At this treatment center, the administration conducts quarterly surveys regarding the status of the clients. The treatment center has 2 different programs; a residential and an outpatient. This survey is then entered into a data set. The data set has a string variable indicating the type of record of each survey administration. The variable is coded as A-admit, Q-quarter, D-discharge, and T-transfer. The transfer (T) is what is currently causing some issues. When someone receives a T, that means they have transferred from the residential to the outpatient. I want to take that T and create (duplicate) 2 additional records (cases), so the T becomes a residential discharge (DR) and a outpatient admit (AO). Below is a sample of the data. > > ID Number RecType PrgmType Var1 Var2 Var3 > 001 A 1 20 10 15 > 001 Q 1 20 10 15 > 001 Q 1 15 10 0 > 001 T 1 10 5 0 > 001 Q 2 5 5 0 > 001 D 2 5 0 0 > > > Values > Rectype-String PrgmType-numeric Var1-3-numeric > A-Admit 1=residential =scores on survey items > Q-Quarter 2=outpatient > T-Transfer > D-Discharge > > Thanks for your help with this issue. > > > --------------------------------- > Food fight? Enjoy some healthy debate > in the Yahoo! Answers Food & Drink Q&A. |
Free forum by Nabble | Edit this page |