Desktop productivity for business analysts and programmers

Create date variable from week, month, year

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Create date variable from week, month, year

I have week, month, and year variables and need to create a date variable from these.  Suggestions on how to do this?


Accepted Solutions
Solution
‎06-13-2014 02:48 PM
Super User
Posts: 19,165

Re: Create date variable from week, month, year

Aligns to the beginning of the week;

date=mdy(1,1,year)+(week-1)*7;

OR

intnx('week', mdy(1,1, year), week, 'middle');

And look at the alignment options for intnx function, ie beginning end, middle.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

View solution in original post


All Replies
Super User
Posts: 19,165

Re: Create date variable from week, month, year

How does your week look, it is 25 indicating 25th week of the year or 2 indicating the 2nd week of a month?

Assuming its between 1 and 5

something like the following may work:

date=mdy(month, 7*(week-1)+1   , year);

Occasional Contributor
Posts: 14

Re: Create date variable from week, month, year

It is numbered 0 through 52, so 25 indicates the 25th week of the year.

Super User
Posts: 11,134

Re: Create date variable from week, month, year

Would you like the date to reflect any specific day of the week?

Occasional Contributor
Posts: 14

Re: Create date variable from week, month, year

Thursdays preferably, but if it is too difficult that way it doesn't particularly matter that much.

Super User
Posts: 19,165

Re: Create date variable from week, month, year

Weeks can cross months so having a specific day may not be possible

Occasional Contributor
Posts: 14

Re: Create date variable from week, month, year

Even just an approximate day would be ok.

e.g.

wk 1 = 1/1/14

wk 2 = 1/8/14

wk 3 = 1/15/14

etc.

Solution
‎06-13-2014 02:48 PM
Super User
Posts: 19,165

Re: Create date variable from week, month, year

Aligns to the beginning of the week;

date=mdy(1,1,year)+(week-1)*7;

OR

intnx('week', mdy(1,1, year), week, 'middle');

And look at the alignment options for intnx function, ie beginning end, middle.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 472 views
  • 1 like
  • 3 in conversation