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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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