BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JJ_83
Obsidian | Level 7
  1. First, I want to assign a week number to each week within the range: January 1, 2001 - December 31, 2020
  2. Then I want to assign two date variables (date_01 and date_02) to their corresponding week number.
  3. I want to do #1 and #2 for months instead of weeks.

Any ideas on how to do this easily? I am guessing there is a way to do this in one step instead of 2.

1 ACCEPTED SOLUTION
12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

1) Should the week number of 01Jan2001 be the same as 01jan2002? Or should they be 1 and 53 eg?

 

2) What values should date_1 and date:2 take?

JJ_83
Obsidian | Level 7

1. The week number of 01JAN2001 and 01JAN2002 should be different. 01JAN2002 should have a week number of 53, and so on. Here's what my data looks like.

Capture.PNG

 

2. I already have values for date_1 and date_2, and what I want to do is match the date_1 and date_2 values to the week number for the week that it falls in. For example a date_1 value of 1JAN2001 would have a week value of 1 and a date_2 value of 31DEC2001 would have a week value of 52.

 

 

ballardw
Super User

Basic approach is to start with a SAS date value.

Then it looks like functions WEEKU, WEEKV or WEEKW, which determine "week" by which day starts as week and how to treat things at the beginning of the year, and the MONTH function.

 

But you really need to show some values especially to explain date_01 and date_02. Your description makes them sound like two variables with the same value.

JJ_83
Obsidian | Level 7
  1. The problem I see with the week and month functions is that it returns the week number for the year, but since I have multiple years I need a unique number for each week.
  2. Here is what my data looks like now.

Capture.PNG

Reeza
Super User
What would be the expected output from that data as the input. Exactly please.
Reeza
Super User
Why are you doing this? And do you have access to SAS/ETS?

I suspect there are better ways to do whatever you need here.
ballardw
Super User

@JJ_83 wrote:
  1. The problem I see with the week and month functions is that it returns the week number for the year, but since I have multiple years I need a unique number for each week.
  2. Here is what my data looks like now.

Capture.PNG


Still haven't shown what you expect for the output.

 

You might be looking for INTCK function which returns the count of intervals between two dates:

Weeknumber = intck('week', '01JAN2001'd, somedatevariable);

 

And as I said before your requirement 2 does not make much sense as stated and you really need to supply examples of the output.

You really are not providing many details.

JJ_83
Obsidian | Level 7

Thank you! That's exactly what I needed!

ZigmudLeic
Calcite | Level 5

That could be a problem because of February and it's 28-29 days a month. It was fixed with an additional C++ class in employee monitoring software.

Kurt_Bremser
Super User

The INTCK function takes care of this.

 


@ZigmudLeic wrote:

That could be a problem because of February and it's 28-29 days a month. It was fixed with an additional C++ class in employee monitoring software.


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1280 views
  • 1 like
  • 6 in conversation