WEEKDATE9 returning wrong day of week

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

WEEKDATE9 returning wrong day of week

I'm having issues with WEEKDATE9. returning the wrong day of the week for me. For example, today is Wednesday, however it returns Tuesday for me.

 

Below is my code. My input is in the format of yy.ddd hence the CAT/SUBSTR to remove the period -  

 

DateJulian = cat((substr(Date, 1,2)),(substr(Date, 4,3)));    

DateNew    = datejul(DateJulian);                              

DayOfWeek  = weekday(DateNew);                                 

format datenew mmddyy10.;                                     

format DayOfWeek weekdate9.;

 

Without the format WEEKDATE9. line, it does return the correct integer. That is, for today, Wednesday, it returns 4. However when I try to format it, I always get the previous day of the week(e.g. for 09/27 I get Tuesday).

 

Any thoughts as to what I'm doing wrong here?


Accepted Solutions
Solution
‎09-27-2017 10:01 AM
Super User
Posts: 9,924

Re: WEEKDATE9 returning wrong day of week

[ Edited ]

By doing this:

DayOfWeek  = weekday(DateNew);

you set dayofweek to the value 4, which, when used as a date:

format DayOfWeek weekdate9.;

corresponds to 1960-01-05, which indeed was a Tuesday.

Keep in mind that the weekdate format is for SAS date values, not for the already calculated weekday value.

Apply the weekdate format to variable datenew.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Respected Advisor
Posts: 2,836

Re: WEEKDATE9 returning wrong day of week

Help us out. Show us your input. Show us the the relevant portions of your code instead of this code fragment.

--
Paige Miller
Contributor
Posts: 20

Re: WEEKDATE9 returning wrong day of week

Posted in reply to PaigeMiller

Here is an example of one line from my input file(#1 msg as defined in File2). I haven't included those lines defined by #2 - #6. 

 

*** blah blah blah                               ***             DATE=17.270  TIME=07:45:08

 

 

This is the code as requested - 

 

 

data File2; 
infile tempFILE; 
input #1 msg $ 03-41 
Date $ 60-65 
Time $ 73-80 
#2 Allowed $ 30-34 
#3 LastAss $ 30-34 
#4 HighAss $ 30-34 
#5 CurrAssCount $ 30-34 
#6 PercentUsed $ 30-34 
; 

/* Remove the period from the julian date, and reformat it */ 
DateJulian = cat((substr(Date, 1,2)),(substr(Date, 4,3))); 
DateNew = datejul(DateJulian); 
DayOfWeek = weekday(DateNew); 
format datenew mmddyy10.; 
format DayOfWeek weekdate9.;

put dateNew dayofweek; 

The output from that put statment is - 

 

09/27/2017 Tuesday 

 

 

Thanks

 

Solution
‎09-27-2017 10:01 AM
Super User
Posts: 9,924

Re: WEEKDATE9 returning wrong day of week

[ Edited ]

By doing this:

DayOfWeek  = weekday(DateNew);

you set dayofweek to the value 4, which, when used as a date:

format DayOfWeek weekdate9.;

corresponds to 1960-01-05, which indeed was a Tuesday.

Keep in mind that the weekdate format is for SAS date values, not for the already calculated weekday value.

Apply the weekdate format to variable datenew.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 20

Re: WEEKDATE9 returning wrong day of week

Posted in reply to KurtBremser

Thanks Kurt. That did it for me.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 232 views
  • 0 likes
  • 3 in conversation