BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
claireluen
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

7 REPLIES 7
Reeza
Super User

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);

claireluen
Calcite | Level 5

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

ballardw
Super User

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

claireluen
Calcite | Level 5

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

Reeza
Super User

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

claireluen
Calcite | Level 5

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.

Reeza
Super User

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 7 replies
  • 2715 views
  • 1 like
  • 3 in conversation