BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

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
SASKiwi
PROC Star

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.

 

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
SASKiwi
PROC Star

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.

 

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

@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
ballardw
Super User

@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.

 

 

SASKiwi
PROC Star

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.

Tom
Super User Tom
Super User

@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?

SASdevAnneMarie
Barite | Level 11
Thank you very much !
mkeintz
PROC Star

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: 

   SAS® 9.4 Functions and CALL Routines: Reference, Fifth Edition 

 

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

--------------------------

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1958 views
  • 3 likes
  • 6 in conversation