BookmarkSubscribeRSS Feed
sandeepgnv
Calcite | Level 5

Hi, I am new to SAS. I am trying to understand what the below code does.

 

where start_date1>=(today()-weekday(today())+2) - 7*156

 

 

Any help is much appreciated.

 

Thank you in advance.

 

Thanks,

Sandeepgnv

5 REPLIES 5
Kurt_Bremser
Super User
today()-weekday(today())+2

normalizes today's date to the last preceding Tuesday. Then 156 weeks are subtracted, which corresponds to rougly three years.

So it translates to "last Tuesday, three years ago".

sandeepgnv
Calcite | Level 5
That was really quick 🙂
Many Thanks KurtBremser !!

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RahulG
Barite | Level 11

Code is going 3 years back by using factor 7*156  i.e. 7 * (3*52). It is kind of very unusual way to do. 

(today()-weekday(today())+2) is kind of finding last Monday from current date. 

 

 

You can try to use below code to debug it.


data temp; format v1 v2 date9.; v1=(today()-weekday(today())+2) - 7*156; v2=(today()-weekday(today())+2); v3=weekday(today()); v4=7*156; v5=weekday(today())+2; put _all_; run;

 

Shmuel
Garnet | Level 18

today() function enters the system date into a variable.

Today you will get the DEC 12th, 2016 given in a sas date.

The sas date contains the number of days since JAN 1st, 1960.

 

weekday() function gives the day number in a week, IE:

1=sunday, 2=monday etc. or 1=monday, 2=tuesday, etc. - depending on your sas system.

 

Youe expression: where start_date1>=(today()-weekday(today())+2) - 7*156

means: check variable start_date1 is it greater or equal to the calculated date

(today - 4 (=wednsday) + 2) - 7*156.

To unswer, why is such calculation, you need ask the one who gave it to you.

 

 

SuryaKiran
Meteorite | Level 14

This type of calculation dosen't give accurate value. Since 1 year ^= 365 days or 1 year ^= 52 weeks.

Thanks,
Suryakiran

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 2523 views
  • 1 like
  • 5 in conversation