BookmarkSubscribeRSS Feed
TMorville
Calcite | Level 5
Hello everyone.

I have a dataset with approx 15000 observations, that all have a date marking like "13MAY2010" but distributed over several months.

What i would like SAS to do, is to recognize each date, and then give a new variable called "week" the weeknumber. An example could be, that 13MAY2010 would be marked with "23" because its the 23 week of 2010.

I've googled all morning and searched though the forum with no luck.

Thanks a bunch!
5 REPLIES 5
deleted_user
Not applicable
Hm, I might be missing something but I think this is fairly simple, ie. I would create a new variable in a data step:

data new; set old;
wn=week(mydate);

Now, to me 13MAY2010 would indicate week # 19, but I guess it depends on if the week starts on a Sunday or a Monday...

Cheers!
TMorville
Calcite | Level 5
Ha!

That did work. Simple enough. Thanks!
deleted_user
Not applicable
Yess! You made my day - I was able to help someone 😉
TMorville
Calcite | Level 5
So. Now im at a new standstill..

Is there anyway to redefine the week() function, so that the week starts every monday?
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello TMorville,

SAS help says that it is necessary to use "V" or "W" descriptor to switch to Monday, say:

Week("01Feb2010"d,"W");

Sincerely,
SPR

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1478 views
  • 0 likes
  • 3 in conversation