DATA Step, Macro, Functions and more

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

Reply
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.

 

Thank you in advance.

 

Thanks,

Sandeepgnv

Super User
Posts: 6,935

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
New Contributor
Posts: 2

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

That was really quick Smiley Happy
Many Thanks KurtBremser !!

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Regular Contributor
Posts: 241

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;

 

Trusted Advisor
Posts: 1,372

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.

 

 

Frequent Contributor
Posts: 117

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

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

Ask a Question
Discussion stats
  • 5 replies
  • 288 views
  • 1 like
  • 5 in conversation