SPSS tutorials

BASICS REGRESSION T-TEST ANOVA CORRELATION

SPSS Computes Wrong Week Numbers?

SPSS Week Numbers Wrong

While working on data holding a record for each day, I wanted to create some graphs on week level. So I extracted the weeks with XDATE.WEEK but the week numbers returned by SPSS are nonsensical: every week starts on January 1 and most years end up with week 53 holding just 1 day. There's different standards for week numbers but I think the very definition of a week is a 7 day time span. The following syntax demonstrates the problem.

SPSS Week Numbers Syntax Example

*Create 500 empty cases.

input program.
loop mydate = 1 to 500.
end case.
end loop.
end file.
end input program.
execute.

*Convert mydate into actual date.

compute mydate = datesum(date.dmy(1,1,2013),mydate - 1,'days').
formats mydate (date11).

*Extract week and year from mydate.

compute week = xdate.week(mydate).
execute.

The result in data view may look normal at first. However, when we scroll down to case 365, we see that week 53 consists of 1 day. Like so, SPSS’ week numbers don't correspond to any conventional standard and can neither be converted into one.

Isoweeks in GoogleDocs

Interestingly, GoogleDocs has the isoweeknum function returning the isoweeks I'm looking for. So a “workable solution” seemed to copy-paste these into an SPSS data file. Finally, MATCH FILES by date seemed to do the trick. And then I realized...
In the isoweek system, dates around new year’s can fall into a week from a different year. And unfortunately, GoogleDocs does not provide the years to which weeks belong. The screenshot below attempts to illustrate the problem.

SPSS Week Numbers Googledocs Years

Right. So extracting the year from December 30, 2013 obviously returns 2013. However, it falls in week 1, 2014. And neither SPSS nor GoogleDocs offers a function that'll insert 2014 into my dataset for this date.

Solution

Nope, no solution so far. I could go and look for a huge table holding a long date range and all isoweeks plus the years in which they fall. And convert it to SPSS. And merge it into several data files. But I'd much rather avoid such an ugly solution.
So... any suggestions anybody? Please drop me a comment below if you've a better idea.

Thanks!

Previous tutorial: New Charts in SPSS 25: How Good Are They Really?

Next tutorial: SPSS – How to fix “Your license will expire in … days”?

Let me know what you think!

*Required field. Your comment will show up after approval from a moderator.

This tutorial has 6 comments