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

I'm new to sas and would like learn to calculate:

How many days in the first week of the year?

For example:

Year = 2016, Week = 1

num_days: 2 days

Year = 2020, week = 1

num_days: 4 days

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @alo_moon and welcome to the SAS Support Communities!

 

You can use the WEEKDAY function (together with the MDY function and a simple calculation) to get the desired result:

data want;
input year;
num_days=8-weekday(mdy(1,1,year));
cards;
2016
2020
;

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @alo_moon and welcome to the SAS Support Communities!

 

You can use the WEEKDAY function (together with the MDY function and a simple calculation) to get the desired result:

data want;
input year;
num_days=8-weekday(mdy(1,1,year));
cards;
2016
2020
;
Ksharp
Super User
data want;
input year;
date=mdy(1,1,year);
num_days=intnx('week',date,1)-date;
cards;
2016
2020
;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 651 views
  • 4 likes
  • 3 in conversation