|
Hello,
I would like to create a data with consecutive numbers by var1 (created), for example: Var1 Varnew 1 1 1 2 1 3 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 3 4 How to do this in syntax? Thanks. Auberth Hurtado ===================== 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 |
|
At 02:55 PM 11/13/2007, Auberth Hurtado wrote:
>I would like to create a data with consecutive numbers by var1 >(created), for example: > >Var1 Varnew >1 1 >1 2 >1 3 >2 1 >2 2 >2 3 >2 4 >2 5 >3 1 >3 2 >3 3 >3 4 transformation-language logic. The following is SPSS 14 draft output (WRR:not saved separately), creating variable 'NewSeq': |-----------------------------|---------------------------| |Output Created |13-NOV-2007 22:36:22 | |-----------------------------|---------------------------| Var1 Varnew 1 1 1 2 1 3 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 3 4 Number of cases read: 12 Number of cases listed: 12 COMPUTE NOBREAK = 1. FORMATS NOBREAK (F2). SPLIT FILE BY var1. CREATE NewSeq = CSUM(NOBREAK). Create |-----------------------------|---------------------------| |Output Created |13-NOV-2007 22:36:22 | |-----------------------------|---------------------------| Created Series |----|-|------|--------------------|----------|-------------| |Var1| |Series|Case Number of |N of Valid|Creating | | | |Name |Non-Missing Values |Cases |Function | | | | |---------------|----| | | | | | |First |Last| | | |----|-|------|---------------|----|----------|-------------| |1 |1|NewSeq|1 |3 |3 |CSUM(NOBREAK)| |2 |1|NewSeq|4 |8 |5 |CSUM(NOBREAK)| |3 |1|NewSeq|9 |12 |4 |CSUM(NOBREAK)| |----|-|------|---------------|----|----------|-------------| SPLIT FILE OFF. LIST. List |-----------------------------|---------------------------| |Output Created |13-NOV-2007 22:36:53 | |-----------------------------|---------------------------| Var1 Varnew NOBREAK NewSeq 1 1 1 1 1 2 1 2 1 3 1 3 2 1 1 1 2 2 1 2 2 3 1 3 2 4 1 4 2 5 1 5 3 1 1 1 3 2 1 2 3 3 1 3 3 4 1 4 Number of cases read: 12 Number of cases listed: 12 =================== APPENDIX: Test data =================== DATA LIST LIST /Var1 Varnew (2F3). BEGIN DATA 1 1 1 2 1 3 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 3 4 END DATA. LIST. ===================== 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 |
|
Hi
I think this solution is simpler: * Sample dataset *. DATA LIST FREE/Var1(F4). BEGIN DATA 1 1 1 2 2 2 2 2 3 3 3 3 END DATA. LIST. COMPUTE id=$casenum. RANK VARIABLES=ID(A) BY Var1 /RANK INTO Varnew /PRINT=NO . DELETE VARIABLES id. FORMAT Varnew (F4). LIST. Best regards, Marta García-Granero > >> I would like to create a data with consecutive numbers by var1 >> (created), for example: >> >> Var1 Varnew >> 1 1 >> 1 2 >> 1 3 >> 2 1 >> 2 2 >> 2 3 >> 2 4 >> 2 5 >> 3 1 >> 3 2 >> 3 3 >> 3 4 > There are a couple of ways. Here's one using CREATE; or, you can use > transformation-language logic. > > The following is SPSS 14 draft output (WRR:not saved separately), > creating variable 'NewSeq': > > |-----------------------------|---------------------------| > |Output Created |13-NOV-2007 22:36:22 | > |-----------------------------|---------------------------| > Var1 Varnew > > 1 1 > 1 2 > 1 3 > 2 1 > 2 2 > 2 3 > 2 4 > 2 5 > 3 1 > 3 2 > 3 3 > 3 4 > > Number of cases read: 12 Number of cases listed: 12 > > > COMPUTE NOBREAK = 1. > FORMATS NOBREAK (F2). > > SPLIT FILE BY var1. > > CREATE NewSeq = CSUM(NOBREAK). > > Create > |-----------------------------|---------------------------| > |Output Created |13-NOV-2007 22:36:22 | > |-----------------------------|---------------------------| > Created Series > |----|-|------|--------------------|----------|-------------| > |Var1| |Series|Case Number of |N of Valid|Creating | > | | |Name |Non-Missing Values |Cases |Function | > | | | |---------------|----| | | > | | | |First |Last| | | > |----|-|------|---------------|----|----------|-------------| > |1 |1|NewSeq|1 |3 |3 |CSUM(NOBREAK)| > |2 |1|NewSeq|4 |8 |5 |CSUM(NOBREAK)| > |3 |1|NewSeq|9 |12 |4 |CSUM(NOBREAK)| > |----|-|------|---------------|----|----------|-------------| > > SPLIT FILE OFF. > LIST. > > List > |-----------------------------|---------------------------| > |Output Created |13-NOV-2007 22:36:53 | > |-----------------------------|---------------------------| > Var1 Varnew NOBREAK NewSeq > > 1 1 1 1 > 1 2 1 2 > 1 3 1 3 > 2 1 1 1 > 2 2 1 2 > 2 3 1 3 > 2 4 1 4 > 2 5 1 5 > 3 1 1 1 > 3 2 1 2 > 3 3 1 3 > 3 4 1 4 > > Number of cases read: 12 Number of cases listed: 12 > =================== > APPENDIX: Test data > =================== > DATA LIST LIST /Var1 Varnew (2F3). > BEGIN DATA > 1 1 > 1 2 > 1 3 > 2 1 > 2 2 > 2 3 > 2 4 > 2 5 > 3 1 > 3 2 > 3 3 > 3 4 > END DATA. > LIST. > > ===================== > 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 |
|
At 01:42 AM 11/14/2007, Marta García-Granero wrote:
>I think this solution is simpler: > >* Sample dataset *. >DATA LIST FREE/Var1(F4). >BEGIN DATA >1 1 1 2 2 2 2 2 3 3 3 3 >END DATA. >LIST. > >COMPUTE id=$casenum. >RANK VARIABLES=ID(A) BY Var1 /RANK INTO Varnew /PRINT=NO . >DELETE VARIABLES id. >FORMAT Varnew (F4). >LIST. Ah! Thanks, Marta. I *thought* there was a RANK trick for this, but I couldn't remember it. For completeness, this is how I'd really do it, except I got embarrassed because I seem to use the transformation language all the time. It does have the advantage of not creating any variable that needs to be dropped later. Using your test data, NUMERIC VarNew (F3). DO IF MISSING(LAG(Var1)) OR LAGO(Var1) LT Var1. . COMPUTE VarNew = 1. ELSE. . COMPUTE VarNew = LAG(VarNew) + 1. END IF. LIST. List |-----------------------------|---------------------------| |Output Created |14-NOV-2007 12:06:50 | |-----------------------------|---------------------------| Var1 VarNew 1 1 1 2 1 3 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 3 4 Number of cases read: 12 Number of cases listed: 12 ===================== 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 |
|
In reply to this post by Marta Garcia-Granero
Thanks marta and Richard for your help.
-----Mensaje original----- De: SPSSX(r) Discussion [mailto:[hidden email]] En nombre de Marta García-Granero Enviado el: Miércoles, 14 de Noviembre de 2007 01:42 a.m. Para: [hidden email] Asunto: Re: Consecutive numbers of different size Hi I think this solution is simpler: * Sample dataset *. DATA LIST FREE/Var1(F4). BEGIN DATA 1 1 1 2 2 2 2 2 3 3 3 3 END DATA. LIST. COMPUTE id=$casenum. RANK VARIABLES=ID(A) BY Var1 /RANK INTO Varnew /PRINT=NO . DELETE VARIABLES id. FORMAT Varnew (F4). LIST. Best regards, Marta García-Granero > >> I would like to create a data with consecutive numbers by var1 >> (created), for example: >> >> Var1 Varnew >> 1 1 >> 1 2 >> 1 3 >> 2 1 >> 2 2 >> 2 3 >> 2 4 >> 2 5 >> 3 1 >> 3 2 >> 3 3 >> 3 4 > There are a couple of ways. Here's one using CREATE; or, you can use > transformation-language logic. > > The following is SPSS 14 draft output (WRR:not saved separately), > creating variable 'NewSeq': > > |-----------------------------|---------------------------| > |Output Created |13-NOV-2007 22:36:22 | > |-----------------------------|---------------------------| > Var1 Varnew > > 1 1 > 1 2 > 1 3 > 2 1 > 2 2 > 2 3 > 2 4 > 2 5 > 3 1 > 3 2 > 3 3 > 3 4 > > Number of cases read: 12 Number of cases listed: 12 > > > COMPUTE NOBREAK = 1. > FORMATS NOBREAK (F2). > > SPLIT FILE BY var1. > > CREATE NewSeq = CSUM(NOBREAK). > > Create > |-----------------------------|---------------------------| > |Output Created |13-NOV-2007 22:36:22 | > |-----------------------------|---------------------------| > Created Series > |----|-|------|--------------------|----------|-------------| > |Var1| |Series|Case Number of |N of Valid|Creating | > | | |Name |Non-Missing Values |Cases |Function | > | | | |---------------|----| | | > | | | |First |Last| | | > |----|-|------|---------------|----|----------|-------------| > |1 |1|NewSeq|1 |3 |3 |CSUM(NOBREAK)| > |2 |1|NewSeq|4 |8 |5 |CSUM(NOBREAK)| > |3 |1|NewSeq|9 |12 |4 |CSUM(NOBREAK)| > |----|-|------|---------------|----|----------|-------------| > > SPLIT FILE OFF. > LIST. > > List > |-----------------------------|---------------------------| > |Output Created |13-NOV-2007 22:36:53 | > |-----------------------------|---------------------------| > Var1 Varnew NOBREAK NewSeq > > 1 1 1 1 > 1 2 1 2 > 1 3 1 3 > 2 1 1 1 > 2 2 1 2 > 2 3 1 3 > 2 4 1 4 > 2 5 1 5 > 3 1 1 1 > 3 2 1 2 > 3 3 1 3 > 3 4 1 4 > > Number of cases read: 12 Number of cases listed: 12 > =================== > APPENDIX: Test data > =================== > DATA LIST LIST /Var1 Varnew (2F3). > BEGIN DATA > 1 1 > 1 2 > 1 3 > 2 1 > 2 2 > 2 3 > 2 4 > 2 5 > 3 1 > 3 2 > 3 3 > 3 4 > END DATA. > LIST. > > ===================== > 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 ===================== 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 |
| Free forum by Nabble | Edit this page |
