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

Hello..

Quick Example:

Date A = 31Dec2012

Date B = 12Dec2012

Then I want to know which nth Weekday Date A is since Date B

In this example Date A would be the 3rd Monday since Date B.

Is there anyway to calculate this automatically? Output like 3-2 (3rd-Monday)

Regards,

Raphael

1 ACCEPTED SOLUTION

Accepted Solutions
Raphael_
Calcite | Level 5

DATA _NULL_;

  DATEA='31DEC2012'D;

  DATEB='12DEC2012'D;

  VAR=COMPRESS(INTCK('WEEK', DATEB, DATEA)||"-"||WEEKDAY(DATEA));

  PUT VAR;

RUN;

View solution in original post

6 REPLIES 6
ballardw
Super User

You may be able to accomplish this using a combination of INTCK which returns intervals between SAS date values such as weeks, and the WEEKDAY function which will return day of the week of a SAS date value. Check the online help for syntax, intervals supported and starts (not everyone considers the week to start on the same day).

Raphael_
Calcite | Level 5

It doesn't matter in this situation on which day the week starts. "Check online help"-Answers are useless. Thanks anyway.

NickR
Quartz | Level 8

Check out the below code and see if it works for you.

data one;

  length output $10;

  date_a = '31Dec2012'd;

  date_b = '12Dec2012'd;

  weeka = week(date_a,'u');

  weekdaya = weekday(date_a);

  weekb = week(date_b,'u');

  output = strip(put(weeka-weekb,best.))||'-'||strip(put(weekdaya,best.));

  format date_a date_b date9.;

run;

Raphael_
Calcite | Level 5

Bit complicated :smileysilly:

Will post my solution.. Bit smaller.. But thanks Smiley Wink

Raphael_
Calcite | Level 5

DATA _NULL_;

  DATEA='31DEC2012'D;

  DATEB='12DEC2012'D;

  VAR=COMPRESS(INTCK('WEEK', DATEB, DATEA)||"-"||WEEKDAY(DATEA));

  PUT VAR;

RUN;

Reeza
Super User

Don't feed the trolls...

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!

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