Hi Folks,
I read in the SAS Online Documentation regarding the "weekday-function" the following:
"The WEEKDAY function produces an integer that represents the day of the week, where 1=Sunday, 2=Monday, ..., 7=Saturday."
When I run the following code, I get WRONG weekdays as soon as I put a weekday-Format on the calculated weekday.
Data input;
format date date9. ;
input date ;
datalines;
21400
21401
21402
21403
21404
;
run;
data weekdays_wrong;
set input;
weekday = weekday(date);
weekday2 = weekday(date);
weekday3 = weekday(date);
format weekday2 weekday9. weekday3 weekdate9.;
run;
Correctly, the 4th of August 2018 was a SATURDAY (which corresponds to the integer "7", so the weekday-function works!) . But SAS assigns a Friday (integer = "6") as soon as I want to put a format - no matter if I use "weekday9." or "weekdate9." for example - on the calculated weekday!
What am I missing? Does it have to do something with the Nation Language Support? I would like to get the weekdays in German language (I think, I have to use the "NLDATEWN" format)? Would that mean, that I have to set the option
options LOCALE=DE_DE;
By default, we have set options LOCALE=US_EN. I vaguely remember that Americans vs. Germans start counting the week by a 1 day difference.....
Any help would gladly be appreciated.
Thanks,
FK1
You are missing the fact that the formats need to be applied to a date, not a weekday number. If you use those formats on a weekday number, you get the weekdays of the first seven days of 1960.
You are missing the fact that the formats need to be applied to a date, not a weekday number. If you use those formats on a weekday number, you get the weekdays of the first seven days of 1960.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.