Help using Base SAS procedures

Getting SAS to recognize weeks

Reply
Contributor
Posts: 43

Getting SAS to recognize weeks

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!
N/A
Posts: 0

Re: Getting SAS to recognize weeks

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!
Contributor
Posts: 43

Re: Getting SAS to recognize weeks

Ha!

That did work. Simple enough. Thanks!
N/A
Posts: 0

Re: Getting SAS to recognize weeks

Yess! You made my day - I was able to help someone ;-)
Contributor
Posts: 43

Re: Getting SAS to recognize weeks

So. Now im at a new standstill..

Is there anyway to redefine the week() function, so that the week starts every monday?
Super Contributor
Super Contributor
Posts: 365

Re: Getting SAS to recognize weeks

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
Ask a Question
Discussion stats
  • 5 replies
  • 149 views
  • 0 likes
  • 3 in conversation