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