Barite | Level 11

## Week function

Hello Experts,

I would like to get the real number of the week. Do I need to use week(Date,'v') ?

Thank you !

1 ACCEPTED SOLUTION

Accepted Solutions
PROC Star

## Re: Week function

What do you mean by "real number of the week"? There are different recognised definitions for week number and you need to decide which one to use. The SAS doc explains the definitions.

Here is a link to the ISO definition of week number (week date): https://en.wikipedia.org/wiki/ISO_week_date

The SAS 'V' method gives the ISO definition.

9 REPLIES 9
Diamond | Level 26

## Re: Week function

You could use week(Date,'v') or week(Date,'w') or week(Date,'u'), whichever works for you.

--
Paige Miller
PROC Star

## Re: Week function

What do you mean by "real number of the week"? There are different recognised definitions for week number and you need to decide which one to use. The SAS doc explains the definitions.

Here is a link to the ISO definition of week number (week date): https://en.wikipedia.org/wiki/ISO_week_date

The SAS 'V' method gives the ISO definition.

Barite | Level 11

## Re: Week function

Thank you for your answear, I would like to have the first week with number 1, not 0.
Diamond | Level 26

## Re: Week function

@SASdevAnneMarie wrote:
Thank you for your answear, I would like to have the first week with number 1, not 0.

Not sure what this means, first week of what year? How do you define first week?

Why don't you just add 1 to the week zero answer you are getting?

Anyway, if I were you, I would try the three different options of the WEEK function and see if one of them does what you want.

--
Paige Miller
Super User

## Re: Week function

@SASdevAnneMarie wrote:
Thank you for your answear, I would like to have the first week with number 1, not 0.

Rules for "first week". For example first week of what? Calendar year? Fiscal Year? Month? Calendar quarter?

Example data values, I have to assume dates, as a working data step and the expected result. Read the documentation on the week function and the U V and W options. If one of them matches use it. If not, describe what you actually want with values and rules.

PROC Star

## Re: Week function

According to the WEEK function doc the 'V' option counts from 1. The U and W options start from 0. As I already mentioned the V option does the ISO definition.

Super User

## Re: Week function

@SASdevAnneMarie wrote:
Thank you for your answear, I would like to have the first week with number 1, not 0.

First week of what interval? A year? A month?

What day of the week does a week start on?  Is it Sunday?  Or do weeks always start of the day of the week that Jan01 falls on?

What do you do with partial week at the start of a year?  Say Jan01 is on a Tuesday?  does that mean that week 1 only has 5 days (from Tuesday to Saturday) instead of 7 days?  Or does week one has 12 days instead of 7?

What do you do with partial week at the end of the year?  Take the year 2012, that started on a Sunday.  Does that mean the Dec30 and 31 are part of week 53 for 2012? Or are they part of week 1 for 2013?

Barite | Level 11

## Re: Week function

Thank you very much !
PROC Star

## Re: Week function

One of the best skills a SAS user can develop is flexible use of the internet.

A search (using duckduckgo) for

sas week function 9.4

(I include "9.4' in the search because without it, usually versi0n 9.3 documentation shows up first).

This yields a number of promising links, one of which is a pdf file:

See page 1610 of the above.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Discussion stats
• 9 replies
• 941 views
• 3 likes
• 6 in conversation