BookmarkSubscribeRSS Feed
thegraduate
Calcite | Level 5

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,

9 REPLIES 9
ieva
Pyrite | Level 9

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.

thegraduate
Calcite | Level 5

Thanks for the reply -

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

sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

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.

thegraduate
Calcite | Level 5

can you please provide some more detail?

thanks

art297
Opal | Level 21

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?

thegraduate
Calcite | Level 5

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

art297
Opal | Level 21

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;

ieva
Pyrite | Level 9

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;

art297
Opal | Level 21

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 9 replies
  • 7947 views
  • 0 likes
  • 4 in conversation