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

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 954 views
  • 0 likes
  • 3 in conversation