I don't think I understand exactly how this piece of code works:
if (1 < weekday(date_accident)< 7) then calc_date_accident = date_accident-1; else calc_date_accident = date_accident;
I understand what it is doing-I know that it is subtracting one day from the date_accident variable, but I don't think I understand what is happening in the "IF" statement, specifically the 1 and 7.
Can someone please explain what this code is actually saying?
thanks in advance
The expression is a shorthand for
1 < weekday(date_accident) and weekday(date_accident) < 7
you could also say
IF weekday(date_accident) NOT IN (1 7);
Not Saturday or Sunday. See the WEEKDAY() function documentation.
The expression is a shorthand for
1 < weekday(date_accident) and weekday(date_accident) < 7
you could also say
IF weekday(date_accident) NOT IN (1 7);
Not Saturday or Sunday. See the WEEKDAY() function documentation.
thanks @data_null__!
So the 1 and the 7 actually represents Saturday and Sunday?
Does that mean I can select any day of the week by using these numbers in conjuction with "weekday". So for example if I wanted to select Wednesday I would choose the number 4?
@confused_saser wrote:
thanks @data_null__!
So the 1 and the 7 actually represents Saturday and Sunday?
Does that mean I can select any day of the week by using these numbers in conjuction with "weekday". So for example if I wanted to select Wednesday I would choose the number 4?
I'm sorry, I assumed you had looked at the documention for the WEEKDAY function and knew what it was returning. Yes today, Wednesday, is weekday 4.
I should have looked it up but I actualyl dind't realize it was a function.
Super new to SAS! thank you 🙂
@confused_saser wrote:
I should have looked it up but I actualyl dind't realize it was a function.
Super new to SAS! thank you 🙂
I thought your confusion was with the expression 1 < value < 7, it was for me. I had to write an example to make sure I knew what it was doing.
data acc;
do date_accident = today() to today()+10;
weekday = weekday(date_accident);
x = 1 < weekday(date_accident)< 7;
y = 1 < weekday(date_accident) and weekday(date_accident) < 7;
z = weekday(date_accident) not in (1 7);
if (1 < weekday(date_accident)< 7) then calc_date_accident = date_accident-1;
else calc_date_accident = date_accident;
output;
end;
run;
proc print;
run;
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.
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.