BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
serge68
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
serge68
Calcite | Level 5

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

 

Kurt_Bremser
Super User

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.

serge68
Calcite | Level 5

Thanks Kurt. That did it for me.

 

sas-innovate-2024.png

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.

 

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
  • 4 replies
  • 2102 views
  • 1 like
  • 3 in conversation