compute for selected IDs

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

compute for selected IDs

Jeff A

 

I have a dataset with an ID variable (numeric). I want to run a compute statement to alter a variable for a given list of IDs. How do I do this in the easiest and most efficient manner.

 

E.g., something like this:

 

 

For ID = 3, 4, 66, 99, 333, 444, etc.

Compute Finished = 1.

End for.

 

I assume some type of macro, but perhaps there is a more straightforward way.

 

Best,

 

Jeff

 

===================== 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: compute for selected IDs

Kirill Orlov
IF ANY(ID, 3, 4, 66, 99, 333, 444) Finished= 1.

23.12.2018 10:39, Jeff пишет:

 

I have a dataset with an ID variable (numeric). I want to run a compute statement to alter a variable for a given list of IDs. How do I do this in the easiest and most efficient manner.

 

E.g., something like this:

 

 

For ID = 3, 4, 66, 99, 333, 444, etc.

Compute Finished = 1.

End for.

 

I assume some type of macro, but perhaps there is a more straightforward way.

 

Best,

 

Jeff

 

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: compute for selected IDs

Jon Peck
Kirill's solution is fine if the number of IDs is moderate.  If the list is very long, it would be more convenient and less error prone to construct a second dataset of the relevant id's and match that against the original data to define the selection criteria.

On Sun, Dec 23, 2018 at 1:58 AM Kirill Orlov <[hidden email]> wrote:
IF ANY(ID, 3, 4, 66, 99, 333, 444) Finished= 1.

23.12.2018 10:39, Jeff пишет:

 

I have a dataset with an ID variable (numeric). I want to run a compute statement to alter a variable for a given list of IDs. How do I do this in the easiest and most efficient manner.

 

E.g., something like this:

 

 

For ID = 3, 4, 66, 99, 333, 444, etc.

Compute Finished = 1.

End for.

 

I assume some type of macro, but perhaps there is a more straightforward way.

 

Best,

 

Jeff

 

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


--
Jon K Peck
[hidden email]

===================== 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: compute for selected IDs

Art Kendall
In order to preserve sysmis to its purpose

if it is only a few IDs
DO IF ANY(ID, 3, 4, 66, 99, 333, 444)
compute Finished= 1.
else.
Compute Finished =0.
end if.
numeric finished (f1).
Variable labels Finished 'XYZ finished or not'.
value labels Finished
1 'Yes'
2 'No'

If there are many IDs as Jon said put those IDs in a dataset.

numeric finished (f1).
compute finished = 0.
UPDATE . .
Variable labels Finished 'XYZ finished or not'.
value labels Finished
1 'Yes'
2 'No'





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: compute for selected IDs

David Marso-2
In reply to this post by Jeff A
COMPUTE Finished= ANY(ID, 3, 4, 66, 99, 333, 444) .

=====================
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: compute for selected IDs

Art Kendall
compact and elegant.

Readability, clarity?

Also variable still would need labels.




-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: compute for selected IDs

Bruce Weaver
Administrator
Art is responding to David's suggested COMPUTE command:

COMPUTE Finished= ANY(ID, 3, 4, 66, 99, 333, 444) .

The clarity Art is asking for could be achieved by adding a simple comment.
E.g.,

COMPUTE Finished= ANY(ID, 3, 4, 66, 99, 333, 444) .
* If ID is in the list, Finished=1, else Finished=0.

SPSS veterans will likely know that, but less experienced users may not.



Art Kendall wrote

> compact and elegant.
>
> Readability, clarity?
>
> Also variable still would need labels.
>
>
>
>
> -----
> Art Kendall
> Social Research Consultants
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.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
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: compute for selected IDs

Jon Peck
Good comments clarify the purpose and context of the code.
"These IDs refer to Canadians, who are otherwise not otherwise identified in the data"
Bad comments just repeat what the code says and are clutter making it hard to read a whole coherent block of code.

Which would you rather read here six months from now when you are trying to figure this out?

On Sun, Dec 23, 2018 at 6:31 PM Bruce Weaver <[hidden email]> wrote:
Art is responding to David's suggested COMPUTE command:

COMPUTE Finished= ANY(ID, 3, 4, 66, 99, 333, 444) .

The clarity Art is asking for could be achieved by adding a simple comment.
E.g.,

COMPUTE Finished= ANY(ID, 3, 4, 66, 99, 333, 444) .
* If ID is in the list, Finished=1, else Finished=0.

SPSS veterans will likely know that, but less experienced users may not.



Art Kendall wrote
> compact and elegant.
>
> Readability, clarity?
>
> Also variable still would need labels.
>
>
>
>
> -----
> Art Kendall
> Social Research Consultants
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.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


--
Jon K Peck
[hidden email]

===================== 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: compute for selected IDs

Jeff A

 

 

Excellent advise everyone. Thanks

 

An additional question:

 

Can similar be done with a single line of code with a string variable. E.g., * If ID is in the list, Finished=”Yes”, else Finished=”No”. I can’t get it to work with a single line, but need about 3.

 

Best,

 

Jeff

 

 

 

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Jon Peck
Sent: Monday, 24 December 2018 12:41 PM
To: [hidden email]
Subject: Re: compute for selected IDs

 

Good comments clarify the purpose and context of the code.

"These IDs refer to Canadians, who are otherwise not otherwise identified in the data"

Bad comments just repeat what the code says and are clutter making it hard to read a whole coherent block of code.

 

Which would you rather read here six months from now when you are trying to figure this out?

 

On Sun, Dec 23, 2018 at 6:31 PM Bruce Weaver <[hidden email]> wrote:

Art is responding to David's suggested COMPUTE command:

COMPUTE Finished= ANY(ID, 3, 4, 66, 99, 333, 444) .

The clarity Art is asking for could be achieved by adding a simple comment.
E.g.,

COMPUTE Finished= ANY(ID, 3, 4, 66, 99, 333, 444) .
* If ID is in the list, Finished=1, else Finished=0.

SPSS veterans will likely know that, but less experienced users may not.



Art Kendall wrote


> compact and elegant.
>
> Readability, clarity?
>
> Also variable still would need labels.
>
>
>
>
> -----
> Art Kendall
> Social Research Consultants
> --
> Sent from: http://spssx-discussion.1045642.n5.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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.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


 

--

Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: compute for selected IDs

Jeff A
In reply to this post by Jeff A
...normally wouldn't use a string, but need to give selected variables/values to a secretary via an excel file after data analysis and 1/0 format would get confused.




-----Original Message-----
From: David Marso <[hidden email]>
Sent: Thursday, 27 December 2018 2:04 AM
To: [hidden email]; Jeff A <[hidden email]>
Subject: Re: compute for selected IDs

No.
You would need one line to declare the string variable.
Another line to compute a flag.
A third to RECODE into the string.
Why would you prefer a string variable?
<

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