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?
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.
Help us out. Show us your input. Show us the the relevant portions of your code instead of this code fragment.
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
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.
Thanks Kurt. That did it for me.
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.
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.