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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1754 views
  • 1 like
  • 5 in conversation