Help using Base SAS procedures

Display first Day of week from Week Number

Reply
Contributor
Posts: 24

Display first Day of week from Week Number

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,

Frequent Contributor
Posts: 82

Display first Day of week from Week Number

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.

Contributor
Posts: 24

Display first Day of week from Week Number

Thanks for the reply -

I'm after the actual day of the week (first day in week).

Super Contributor
Super Contributor
Posts: 3,174

Display first Day of week from Week Number

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.

Contributor
Posts: 24

Display first Day of week from Week Number

can you please provide some more detail?

thanks

PROC Star
Posts: 7,363

Display first Day of week from Week Number

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?

Contributor
Posts: 24

Display first Day of week from Week Number

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

PROC Star
Posts: 7,363

Display first Day of week from Week Number

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;

Frequent Contributor
Posts: 82

Display first Day of week from Week Number

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;

PROC Star
Posts: 7,363

Display first Day of week from Week Number

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;

Ask a Question
Discussion stats
  • 9 replies
  • 4253 views
  • 0 likes
  • 4 in conversation