String Matches

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: assign max value in long file format

Jon K Peck
Use AGGREGATE breaking on the ID variable.  Choose max as the statistic, and have it add back to each case.

AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=id
  /number_max=MAX(number).

Then you can just do a select if or similar.


Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        "Parise, Carol A." <[hidden email]>
To:        [hidden email]
Date:        05/13/2011 06:21 PM
Subject:        [SPSSX-L] assign max value in long file format
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi all,

Here is yet another "how do i tell SPSS to do this" type of question.

I have a file that looks like this:

ID      Number
1       1
1       2
1       3
1       4
2       1
2       2
3       1
3       2
3       3
3       4
3       5
4       1

etc....some IDs have Numbers range from 1 to 103.

I need to be able to eliminate all IDs that don't have at least Number GE 3.

I was thinking that i could compute a MaxNumber which is the maximum number of occurrances.

Using the above data, my result would look like this:

ID      Number          MaxNum
1       1               4
1       2               4
1       3               4
1       4               4
2       1               2
2       2               2
3       1               5
3       2               5
3       3               5
3       4               5
3       5               5
4       1               1


I could then select if MaxNum GE 3 and save my reduced file.

Would someone either: 1) Have code that they are willing to share that can do this,  or 2) Suggest a better option?

Many thanks!
Carol

=====================
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

Reply | Threaded
Open this post in threaded view
|

Re: assign max value in long file format

parisec
geez - I totally forgot about AGGREGATE.  thanks for the reminder
From: Jon K Peck [mailto:[hidden email]]
Sent: Friday, May 13, 2011 5:31 PM
To: Parise, Carol A.
Cc: [hidden email]
Subject: Re: [SPSSX-L] assign max value in long file format

Use AGGREGATE breaking on the ID variable.  Choose max as the statistic, and have it add back to each case.

AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=id
  /number_max=MAX(number).

Then you can just do a select if or similar.


Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        "Parise, Carol A." <[hidden email]>
To:        [hidden email]
Date:        05/13/2011 06:21 PM
Subject:        [SPSSX-L] assign max value in long file format
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi all,

Here is yet another "how do i tell SPSS to do this" type of question.

I have a file that looks like this:

ID      Number
1       1
1       2
1       3
1       4
2       1
2       2
3       1
3       2
3       3
3       4
3       5
4       1

etc....some IDs have Numbers range from 1 to 103.

I need to be able to eliminate all IDs that don't have at least Number GE 3.

I was thinking that i could compute a MaxNumber which is the maximum number of occurrances.

Using the above data, my result would look like this:

ID      Number          MaxNum
1       1               4
1       2               4
1       3               4
1       4               4
2       1               2
2       2               2
3       1               5
3       2               5
3       3               5
3       4               5
3       5               5
4       1               1


I could then select if MaxNum GE 3 and save my reduced file.

Would someone either: 1) Have code that they are willing to share that can do this,  or 2) Suggest a better option?

Many thanks!
Carol

=====================
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

12