if any command in SPSS?

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

if any command in SPSS?

spssstarter
Hi everyone. I have a dataset which has a year variable called year, it can be current year or previous year (e.g 2016 or 2015) and also a variable called site (e.g SSA1, SSA2, SSA3) each site has a corresponding year.  I am now recoding the site to SSA, so now i have year variable with year 2015 or 2016 and the site variable SSA.

What i would like to do is if there is case of year 2015 , i would like to set all the year variable to 2015, so the SSA with year 2016 would have year 2015 as well.

so if i have all current year in the year variable (e.g 2016) it stays the same, so i will have SSA with 2016 for all the cases.


is it possible to achieve that? i tried using
do if any (year, 2015).
compute year=2015.
end if.

this doesnt seem working.

any idea how i can do that?  many thanks for your help
Reply | Threaded
Open this post in threaded view
|

Re: if any command in SPSS?

Bruce Weaver
Administrator
Do you understand that the ANY function is looking across variables within a case (row)?  In other words, the syntax you posted is equivalent to:

DO IF year EQ 2015.
- COMPUTE year=2015.
END IF.

I suspect you are trying to look across several cases that are connected somehow.  It's hard to tell based on what you've said.  You'll be more likely to get good help if you post a small dataset that shows clearly what it looks like now, and what you want it to look like afterwards.  The solution may entail using AGGREGATE (which looks across cases).

HTH.


spssstarter wrote
Hi everyone. I have a dataset which has a year variable called year, it can be current year or previous year (e.g 2016 or 2015) and also a variable called site (e.g SSA1, SSA2, SSA3) each site has a corresponding year.  I am now recoding the site to SSA, so now i have year variable with year 2015 or 2016 and the site variable SSA.

What i would like to do is if there is case of year 2015 , i would like to set all the year variable to 2015, so the SSA with year 2016 would have year 2015 as well.

so if i have all current year in the year variable (e.g 2016) it stays the same, so i will have SSA with 2016 for all the cases.


is it possible to achieve that? i tried using
do if any (year, 2015).
compute year=2015.
end if.

this doesnt seem working.

any idea how i can do that?  many thanks for your help
--
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: if any command in SPSS?

spssstarter
the dataset is like, this is the data i extract from our system, if a site hasn't  submitted, the system shows their last year's data, hence 2015 for SSA1.1, SSA1.2 and 2016 for the rest . If all the sites have submitted the data, we would have year 2016 for all the cases here. so here i have the dataset like below as you can see sites SSA1. have not submitted the data yet.

year     site         cost£
2015    SSA1.1    10.5
2015    SSA1.2    20.1
2016    SSA2.1    5.90
2016    SSA2.2    8.55
2016    SSA3.1    7.90
2016    SSA3.2    5.05

now i recode all sites to SSA as these are the sub-sites to  SSA. now the data set looks like

year     site      cost£
2015    SSA     10.5
2015    SSA     20.1
2016    SSA     5.90
2016    SSA     8.55
2016    SSA     7.90
2016    SSA     5.05

( I have sites like SSB SSC here after recoding i am only listing SSA as an example).

now i am aggregating by year and site and get the total cost for each site,  i would get SSA with 2015 and 2016 which i dont want, so before i am doing the aggregation, i want to do like, if any of the sub-site has not submitted the data, i want the year to be the previous year. if all sub-sites have submitted the data, i want to use their new data, i.e 2016 data.  for instance, i want SSA to have year 2015 here

i can not so if year=2016 and site=SSA year=2015. because if all the sub-sites  have submitted the data at the beginning i would want to use 2016 data.
I hope i made it clearly here and thanks again for any help.

Reply | Threaded
Open this post in threaded view
|

Re: if any command in SPSS?

Bruce Weaver
Administrator
You say, "if a site hasn't  submitted, the system shows their last year's data".  I infer from this that "the system" takes care of it, and there is nothing for you to do in terms of bringing forward the previous year's data if it is missing for this year.  

If that is so, why do you not simply AGGREGATE by Site?  Does that not give the totals you want?  If not, you'll have to have another go at explaining it.  (Providing a more complete example that shows outcomes under different scenarios would also be helpful.)


spssstarter wrote
the dataset is like, this is the data i extract from our system, if a site hasn't  submitted, the system shows their last year's data, hence 2015 for SSA1.1, SSA1.2 and 2016 for the rest . If all the sites have submitted the data, we would have year 2016 for all the cases here. so here i have the dataset like below as you can see sites SSA1. have not submitted the data yet.

year     site         cost£
2015    SSA1.1    10.5
2015    SSA1.2    20.1
2016    SSA2.1    5.90
2016    SSA2.2    8.55
2016    SSA3.1    7.90
2016    SSA3.2    5.05

now i recode all sites to SSA as these are the sub-sites to  SSA. now the data set looks like

year     site      cost£
2015    SSA     10.5
2015    SSA     20.1
2016    SSA     5.90
2016    SSA     8.55
2016    SSA     7.90
2016    SSA     5.05

( I have sites like SSB SSC here after recoding i am only listing SSA as an example).

now i am aggregating by year and site and get the total cost for each site,  i would get SSA with 2015 and 2016 which i dont want, so before i am doing the aggregation, i want to do like, if any of the sub-site has not submitted the data, i want the year to be the previous year. if all sub-sites have submitted the data, i want to use their new data, i.e 2016 data.  for instance, i want SSA to have year 2015 here

i can not so if year=2016 and site=SSA year=2015. because if all the sub-sites  have submitted the data at the beginning i would want to use 2016 data.
I hope i made it clearly here and thanks again for any help.
--
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: if any command in SPSS?

Maguin, Eugene
In reply to this post by spssstarter
So here's your data for two site-groups, SSA and SSB. All the SSB sites have reported 2016 data so you want to compute the 2016 total for SSB. Some of the SSA sites have not yet reported 2016 data and so you want to treat the SSA sites that have reported 2016 data as if their data was for 2015.

String sitegrp(a3).
Compute sitegrp=char.substr(site,1,3).
Execute.
Aggregate outfile=* mode=addvariables/break=sitegrp year/n1=nu.
Aggregate outfile=* mode=addvariables/break=sitegrp/n2=nu.
if (n1 ne n2) year=2015.
Execute.
Aggregate outfile=*/break=sitegrp/sitetotal= sum(cost£).

Gene Maguin


year     site         cost£
2015    SSA1.1    10.5
2015    SSA1.2    20.1
2016    SSA2.1    5.90
2016    SSA2.2    8.55
2016    SSA3.1    7.90
2016    SSA3.2    5.05
2016    SSB1.1    11.5
2016    SSB1.2    30.1
2016    SSB2.1    15.90
2016    SSB2.2    18.55
2016    SSB3.1    17.90
2016    SSB3.2    25.05






-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of spssstarter
Sent: Monday, March 14, 2016 11:37 AM
To: [hidden email]
Subject: Re: if any command in SPSS?

the dataset is like, this is the data i extract from our system, if a site hasn't  submitted, the system shows their last year's data, hence 2015 for SSA1.1, SSA1.2 and 2016 for the rest . If all the sites have submitted the data, we would have year 2016 for all the cases here. so here i have the dataset like below as you can see sites SSA1. have not submitted the data yet.

year     site         cost£
2015    SSA1.1    10.5
2015    SSA1.2    20.1
2016    SSA2.1    5.90
2016    SSA2.2    8.55
2016    SSA3.1    7.90
2016    SSA3.2    5.05

now i recode all sites to SSA as these are the sub-sites to  SSA. now the data set looks like

year     site      cost£
2015    SSA     10.5
2015    SSA     20.1
2016    SSA     5.90
2016    SSA     8.55
2016    SSA     7.90
2016    SSA     5.05

( I have sites like SSB SSC here after recoding i am only listing SSA as an example).

now i am aggregating by year and site and get the total cost for each site, i would get SSA with 2015 and 2016 which i dont want, so before i am doing the aggregation, i want to do like, if any of the sub-site has not submitted the data, i want the year to be the previous year. if all sub-sites have submitted the data, i want to use their new data, i.e 2016 data.  for instance, i want SSA to have year 2015 here

i can not so if year=2016 and site=SSA year=2015. because if all the sub-sites  have submitted the data at the beginning i would want to use 2016 data.
I hope i made it clearly here and thanks again for any help.





--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/if-any-command-in-SPSS-tp5731729p5731732.html
Sent from the SPSSX Discussion mailing list archive at 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

=====================
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: if any command in SPSS?

spssstarter
thank you Gene, yes that is exactly what i want to do.
what i did is created a flag= 1 for SSA if they the year is last year and aggregated using mode add variables to do sum , so if the sum is >0, compute the year to last year for SSA. but i did this separately.

i excluded SSA from the whole dataset and added this back to it. your syntax is more effective and thanks very much!

jenny