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
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".
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;
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.
This type of calculation dosen't give accurate value. Since 1 year ^= 365 days or 1 year ^= 52 weeks.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.