New Contributor
Posts: 2

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

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.

Thanks,

Sandeepgnv

Super User
Posts: 10,259

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

`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".

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 2

Re: where start_date1>=(today()-weekday(today()) 2) - 7*156 --- ??

That was really quick
Many Thanks KurtBremser !!

attachments. -##
Super Contributor
Posts: 271

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

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;``````

Posts: 1,837

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

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.

Valued Guide
Posts: 596