BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FK1
Lapis Lazuli | Level 10 FK1
Lapis Lazuli | Level 10

 

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

FK1
Lapis Lazuli | Level 10 FK1
Lapis Lazuli | Level 10
Thank's Kurt. As it is said in German: "Den Wald vor lauter Bäumen nicht mehr sehen!"

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 1635 views
  • 0 likes
  • 2 in conversation