Hello Experts,
I would like to get the real number of the week. Do I need to use week(Date,'v') ?
Thank you !
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.
You could use week(Date,'v') or week(Date,'w') or week(Date,'u'), whichever works for you.
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 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.
@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.
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.
@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?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: