Hi All,
I am currently using the followig code to produce the week number;
week=INTCK('WEEK',INTNX('YEAR',FinalDateCombined,0),FinalDateCombined)+1;
How can i change the above code to display the first day of the week rather than display the week number?
Thanks,
What exactly do you want to get? Like for each observation mark if it is first day of week or not? Or instead of week number in all places to write date for Monday (like for this week 22AUG2011) or maybe Sunday?
I think you should explore weekday function.
Thanks for the reply -
I'm after the actual day of the week (first day in week).
Look at using a combination of INTNX function (to reset back to the start-date of the particular week) and a PUT function with the DOWNAME. format to get the "day of week".
Scott Barry
SBBWorks, Inc.
can you please provide some more detail?
thanks
Some more detail from you would be helpful as well, particularly an example. Are you looking for the dates of the first workday of each week? Are you looking at 53 week calendar or are you shifting the extra day or 2 into the first or last of 53 weeks? Are you counting holidays as being the first day of the week?
I haven't looked at holidays, although they might be a good idea. it is a 53 week calendar, and as the code states i am literally taking the week number from a date.
So at the moment, for every application, I assign a week number to the date. But the problem with that is the reports would show just the week number (30/31 etc). I would like it to show the date of the first working day within the week (Sunday/Monday).
application 1 | 13/04/2011 | 11/04/2011
where 11/04/2011 is the first day of the week.
Thanks
Are you only trying to achieve something like the following:
data testdates;
input date date9.;
format date wantdate date9.;
wantdate=date-weekday(date)+2;
cards;
13apr2011
19aug2011
23aug2011
;
run;
Code similar to the one from Art, just in case if for Sundays you want the date of previous (not next) Monday, this could help:
data test;
informat date date9.;
format date date9.;
input date;
datalines;
10APR2011
11APR2011
13APR2011
17APR2011
;
run;
data test2 (drop=dif);
set test;
format wantdate date9. wantdate2 date9.;
*difference to Monday as value of weekday function for Monday is 2;
dif=weekday(date)-2;
wantdate=date-dif;
if dif=-1 then wantdate=date-6;
run;
If you need to shift Sundays to Mondays, then you also could just use the ifn function. E.g.:
data testdates;
input date date9.;
format date wantdate date9.;
wantdate=ifn(weekday(date) gt 1,date-weekday(date)+2,
date+1);
cards;
10APR2011
11APR2011
13APR2011
17APR2011
13AUG2011
14AUG2011
15AUG2011
16AUG2011
;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.