I would like to create a variable indicating the count of each case. This is a portion of my cases I have now: ID# StartDate EndDate Status SubStatus 29167 6-Oct-2010 09:56:00 6-Oct-2010 15:06:00 2 4
29167 7-Feb-2011 10:35:00 7-Feb-2011 16:24:00 2 4
29172 4-Mar-2011 12:35:00 7-Mar-2011 08:33:00 2 4
29177 14-Dec-2010 15:47:00 14-Dec-2010 16:00:00 2 4
29177 16-Jun-2011 15:30:00 17-Jun-2011 09:48:00 2 4
29177 13-Jan-2012 11:53:00 17-Jan-2012 10:37:00 2 4
29177 23-Aug-2012 14:57:00 27-Aug-2012 21:18:00 2 4
29183 26-Jun-2010 13:09:00 28-Jun-2010 09:51:00 2 4
29184 16-Mar-2011 12:10:00 16-Mar-2011 12:34:00 2 4
29184 15-Aug-2011 14:20:00 15-Aug-2011 15:01:00 2 4
29184 24-Jan-2012 14:43:00 26-Jan-2012 15:37:00 2 4
29186 20-Dec-2010 11:47:00 20-Dec-2010 13:28:00 2 4
29188 19-Sep-2010 10:45:00 21-Sep-2010 08:37:00 2 4
29188 9-Dec-2010 12:10:00 9-Dec-2010 14:00:00 2 4
29196 28-Jun-2010 16:28:00 29-Jun-2010 08:57:00 2 4
29196 10-Jan-2011 14:45:00 10-Jan-2011 15:02:00 2 4
29197 8-Oct-2010 14:00:00 12-Oct-2010 15:58:00 2 4
I would like to add a column counting each case within each ID# (to look like below) ID# StartDate EndDate Status SubStatus COUNT 29167 6-Oct-2010 09:56:00 6-Oct-2010 15:06:00 2 4 1 29167 7-Feb-2011 10:35:00 7-Feb-2011 16:24:00 2 4 2 29172 4-Mar-2011 12:35:00 7-Mar-2011 08:33:00 2 4 1 29177 14-Dec-2010 15:47:00 14-Dec-2010 16:00:00 2 4 1 29177 16-Jun-2011 15:30:00 17-Jun-2011 09:48:00 2 4 2 29177 13-Jan-2012 11:53:00 17-Jan-2012 10:37:00 2 4 3 29177 23-Aug-2012 14:57:00 27-Aug-2012 21:18:00 2 4 4 29183 26-Jun-2010 13:09:00 28-Jun-2010 09:51:00 2 4 1 29184 16-Mar-2011 12:10:00 16-Mar-2011 12:34:00 2 4 1 29184 15-Aug-2011 14:20:00 15-Aug-2011 15:01:00 2 4 2 29184 24-Jan-2012 14:43:00 26-Jan-2012 15:37:00 2 4 3 29186 20-Dec-2010 11:47:00 20-Dec-2010 13:28:00 2 4 1 29188 19-Sep-2010 10:45:00 21-Sep-2010 08:37:00 2 4 1 29188 9-Dec-2010 12:10:00 9-Dec-2010 14:00:00 2 4 2 29196 28-Jun-2010 16:28:00 29-Jun-2010 08:57:00 2 4 1 29196 10-Jan-2011 14:45:00 10-Jan-2011 15:02:00 2 4 2 29197 8-Oct-2010 14:00:00 12-Oct-2010 15:58:00 2 4 1 Would someone please advise me how to write syntax to do this??? Stella Vasquez, Planner Research & Development 1624 W Adams, Phoenix, AZ 85007 602-542-2272 **The information contained in this communication is privileged and confidential and is intended solely for the individual[s] and/or entities named herein. This information is not to be disseminated. If you have received this message in error, please reply to the sender and notify the sender of the error and then permanently delete the message and sent item. Thank you.** |
SORT CASES BY StartDate(A).
SORT CASES BY ID#(A). RANK VARIABLES = StartDate BY ID# /RANK INTO COUNT. |
In reply to this post by Stella Vasquez
Do if ($casenum eq 1 or id# ne lag(id#)). Compute countn=1. Else. Compute countn=lag(countn)+1. End if. Count is the name of a function and I don’t think you can use that word. Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Stella Vasquez I would like to create a variable indicating the count of each case. This is a portion of my cases I have now: ID# StartDate EndDate Status SubStatus 29167 6-Oct-2010 09:56:00 6-Oct-2010 15:06:00 2 4 29167 7-Feb-2011 10:35:00 7-Feb-2011 16:24:00 2 4 29172 4-Mar-2011 12:35:00 7-Mar-2011 08:33:00 2 4 29177 14-Dec-2010 15:47:00 14-Dec-2010 16:00:00 2 4 29177 16-Jun-2011 15:30:00 17-Jun-2011 09:48:00 2 4 29177 13-Jan-2012 11:53:00 17-Jan-2012 10:37:00 2 4 29177 23-Aug-2012 14:57:00 27-Aug-2012 21:18:00 2 4 29183 26-Jun-2010 13:09:00 28-Jun-2010 09:51:00 2 4 29184 16-Mar-2011 12:10:00 16-Mar-2011 12:34:00 2 4 29184 15-Aug-2011 14:20:00 15-Aug-2011 15:01:00 2 4 29184 24-Jan-2012 14:43:00 26-Jan-2012 15:37:00 2 4 29186 20-Dec-2010 11:47:00 20-Dec-2010 13:28:00 2 4 29188 19-Sep-2010 10:45:00 21-Sep-2010 08:37:00 2 4 29188 9-Dec-2010 12:10:00 9-Dec-2010 14:00:00 2 4 29196 28-Jun-2010 16:28:00 29-Jun-2010 08:57:00 2 4 29196 10-Jan-2011 14:45:00 10-Jan-2011 15:02:00 2 4 29197 8-Oct-2010 14:00:00 12-Oct-2010 15:58:00 2 4 I would like to add a column counting each case within each ID# (to look like below) ID# StartDate EndDate Status SubStatus COUNT 29167 6-Oct-2010 09:56:00 6-Oct-2010 15:06:00 2 4 1 29167 7-Feb-2011 10:35:00 7-Feb-2011 16:24:00 2 4 2 29172 4-Mar-2011 12:35:00 7-Mar-2011 08:33:00 2 4 1 29177 14-Dec-2010 15:47:00 14-Dec-2010 16:00:00 2 4 1 29177 16-Jun-2011 15:30:00 17-Jun-2011 09:48:00 2 4 2 29177 13-Jan-2012 11:53:00 17-Jan-2012 10:37:00 2 4 3 29177 23-Aug-2012 14:57:00 27-Aug-2012 21:18:00 2 4 4 29183 26-Jun-2010 13:09:00 28-Jun-2010 09:51:00 2 4 1 29184 16-Mar-2011 12:10:00 16-Mar-2011 12:34:00 2 4 1 29184 15-Aug-2011 14:20:00 15-Aug-2011 15:01:00 2 4 2 29184 24-Jan-2012 14:43:00 26-Jan-2012 15:37:00 2 4 3 29186 20-Dec-2010 11:47:00 20-Dec-2010 13:28:00 2 4 1 29188 19-Sep-2010 10:45:00 21-Sep-2010 08:37:00 2 4 1 29188 9-Dec-2010 12:10:00 9-Dec-2010 14:00:00 2 4 2 29196 28-Jun-2010 16:28:00 29-Jun-2010 08:57:00 2 4 1 29196 10-Jan-2011 14:45:00 10-Jan-2011 15:02:00 2 4 2 29197 8-Oct-2010 14:00:00 12-Oct-2010 15:58:00 2 4 1 Would someone please advise me how to write syntax to do this??? Stella Vasquez, Planner Research & Development 1624 W Adams, Phoenix, AZ 85007 602-542-2272 **The information contained in this communication is privileged and confidential and is intended solely for the individual[s] and/or entities named herein. This information is not to be disseminated. If you have received this message in error, please reply to the sender and notify the sender of the error and then permanently delete the message and sent item. Thank you.** |
In reply to this post by Stella Vasquez
DATA LIST LIST /id. BEGIN DATA. 1 1 1 2 3 4 5 5 6 7 7. END DATA. compute count eq 1. sort cases by ID. if (lag(ID,1) eq ID) count eq (lag(count,1))+1. execute. Sorting is very important if you’re
using lag functions. From: SPSSX(r)
Discussion [mailto: I
would like to create a variable indicating the count of each case.
This is a portion of my cases I have now: ID#
StartDate
EndDate
Status SubStatus 29167
6-Oct-2010 09:56:00 6-Oct-2010
15:06:00
2
4
29167
7-Feb-2011 10:35:00 7-Feb-2011
16:24:00
2
4 29172
4-Mar-2011 12:35:00 7-Mar-2011
08:33:00
2
4
29177
14-Dec-2010 15:47:00 14-Dec-2010
16:00:00
2
4
29177
16-Jun-2011 15:30:00 17-Jun-2011
09:48:00
2
4
29177
13-Jan-2012 11:53:00 17-Jan-2012
10:37:00
2
4
29177
23-Aug-2012 14:57:00 27-Aug-2012
21:18:00
2
4
29183
26-Jun-2010 13:09:00 28-Jun-2010
09:51:00
2
4
29184
16-Mar-2011 12:10:00 16-Mar-2011 12:34:00
2
4
29184
15-Aug-2011 14:20:00 15-Aug-2011
15:01:00
2
4
29184
24-Jan-2012 14:43:00 26-Jan-2012
15:37:00
2
4
29186
20-Dec-2010 11:47:00 20-Dec-2010
13:28:00
2
4
29188
19-Sep-2010 10:45:00 21-Sep-2010
08:37:00
2
4
29188
9-Dec-2010 12:10:00 9-Dec-2010
14:00:00
2
4
29196
28-Jun-2010 16:28:00 29-Jun-2010
08:57:00
2
4
29196
10-Jan-2011 14:45:00 10-Jan-2011
15:02:00
2
4
29197
8-Oct-2010 14:00:00 12-Oct-2010
15:58:00
2
4
I would
like to add a column counting each case within each ID# (to look like below) ID#
StartDate
EndDate
Status
SubStatus
COUNT 29167
6-Oct-2010 09:56:00 6-Oct-2010
15:06:00
2
4
1 29167
7-Feb-2011 10:35:00 7-Feb-2011
16:24:00
2
4
2 29172
4-Mar-2011 12:35:00 7-Mar-2011 08:33:00
2
4
1 29177
14-Dec-2010 15:47:00 14-Dec-2010
16:00:00
2
4
1 29177
16-Jun-2011 15:30:00 17-Jun-2011
09:48:00 2
4
2 29177
13-Jan-2012 11:53:00 17-Jan-2012
10:37:00
2
4
3 29177
23-Aug-2012 14:57:00 27-Aug-2012
21:18:00
2
4
4 29183
26-Jun-2010 13:09:00 28-Jun-2010
09:51:00
2
4
1 29184
16-Mar-2011 12:10:00 16-Mar-2011 12:34:00
2
4
1 29184
15-Aug-2011 14:20:00 15-Aug-2011
15:01:00
2
4
2 29184
24-Jan-2012 14:43:00 26-Jan-2012
15:37:00
2
4
3 29186
20-Dec-2010 11:47:00 20-Dec-2010
13:28:00
2
4
1 29188
19-Sep-2010 10:45:00 21-Sep-2010
08:37:00
2
4
1 29188
9-Dec-2010 12:10:00 9-Dec-2010
14:00:00
2
4
2 29196
28-Jun-2010 16:28:00 29-Jun-2010
08:57:00
2
4
1 29196
10-Jan-2011 14:45:00 10-Jan-2011
15:02:00
2
4
2 29197
8-Oct-2010 14:00:00 12-Oct-2010
15:58:00
2
4
1 Would
someone please advise me how to write syntax to do this??? Stella
Vasquez, Planner Research
& Development 1624
602-542-2272 **The information contained in this
communication is privileged and confidential and is intended solely for the
individual[s] and/or entities named herein. This information is not to be
disseminated. If you have received this message in error, please reply to the
sender and notify the sender of the error and then permanently delete the
message and sent item. Thank you.** |
Administrator
|
In reply to this post by Ujjawal
SORT CASES can take more than one variable. So you could change that to:
SORT CASES BY ID# StartDate(A). RANK VARIABLES = StartDate BY ID# /RANK INTO COUNT. (TAFKA)SPSS will sort on ID# first, then it will sort on StartDate within the cases for each ID#. As Gene noted, there is a COUNT command, so to avoid confusion, it would be better to use some other variable name. I like using Record or RecNum for this sort of thing. I.e., SORT CASES BY ID# StartDate(A). RANK VARIABLES = StartDate BY ID# /RANK INTO Record. VARIABLE LABELS Record "Record # (within ID#)" . 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/). |
Administrator
|
In reply to this post by Stella Vasquez
data list free /id.
BEGIN DATA 1 1 1 2 3 4 5 5 5 5 5 6 6 7 7 8 END DATA. COMPUTE Counter=1. IF ID EQ LAG(ID) Counter=LAG(Counter)+1. LIST. id Counter 1.00 1.00 1.00 2.00 1.00 3.00 2.00 1.00 3.00 1.00 4.00 1.00 5.00 1.00 5.00 2.00 5.00 3.00 5.00 4.00 5.00 5.00 6.00 1.00 6.00 2.00 7.00 1.00 7.00 2.00 8.00 1.00 Number of cases read: 16 Number of cases listed: 16
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 Bruce Weaver
Thank you for the feedback Bruce. I have noted down the points . I will take care of it next time.
|
Administrator
|
In reply to this post by eharrigan
"Sorting is very important if you’re using lag functions."
INDEED! In this case Stella presented a file which was sorted. If in doubt SORT on the appropriate KEYs before doing any lagging dependent upon file order. --
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?" |
Banned User
|
I will be out of the office until Friday, March 29, 2013, with no access to email. However, please know that your message is very important to me and I will respond when I return.
If this is an emergency, please call our office at 734.459.1030.
Thank you.
Sincerely, Cheryl _____________________________________________________ Cheryl A. Boglarsky, Ph.D. Human Synergistics, Inc. 39819 Plymouth Road Plymouth, MI 48170 734.459.1030
This message includes legally privileged and confidential information that is intended only for the use of the recipient named above. All readers of this message, other than the intended recipient, are hereby notified that any dissemination, modification, distribution or reproduction of this e-mail is strictly forbidden. |
Free forum by Nabble | Edit this page |