Tech Tip: Sort Data by Week Number

There are times when doing reports when you need to sort your values into weeks. Most people would end up writing a program to do this, but that is not necessary.

So assuming attribute 14 contains a date, then

F Correlative
F;14;C7;/ 
A Correlative
A;(14 / "7")

A full dictionary item would like the like the following

WEEK.NBR
001 S
002 0
003 Week Number
008 F;14;C1;+;C7;/
009 R
010 6

is now the week number since 1968, with Sunday as the start of the week. You can then use this in a BREAK-ON.

SORT FILE BY DATE BREAK-ON WEEK.NBR

If you want to have Monday as the beginning of the week, then do the follow:

WEEK.NBR.M-S
001 S
002 0
003 Week Number
008 F;14;C1;-;C7;/
009 R
010 6

If you want to sort based on the week number within the year, use:

WEEK.NBR.IN-YR
001 S
002 0
003 Week Number
008 A;(14 / "7")-(("01/01/":(14(DY)))(DI) / "7")
009 R
010 6

Based on a tip originally by Tom Phillips.

Do you have a Tech Tip to share? E-mail it to editor@intl-spectrum.com

Featured:

Jan/Feb 2012

menu
menu