BookmarkSubscribeRSS Feed
bd_user_10
Quartz | Level 8

Hi Everyone,

 

I have the following dataset:

 

Date 

Sedol

event_day

Calday

31/01/1995

4553275

9/02/1995

-9

1/02/1995

4553275

9/02/1995

-8

2/02/1995

4553275

9/02/1995

-7

3/02/1995

4553275

9/02/1995

-6

6/02/1995

4553275

9/02/1995

-3

7/02/1995

4553275

9/02/1995

-2

8/02/1995

4553275

9/02/1995

-1

9/02/1995

4553275

9/02/1995

0

10/02/1995

4553275

9/02/1995

1

13/02/1995

4553275

9/02/1995

4

14/02/1995

4553275

9/02/1995

5

15/02/1995

4553275

9/02/1995

6

16/02/1995

4553275

9/02/1995

7

17/02/1995

4553275

9/02/1995

8

20/02/1995

4553275

9/02/1995

11

 

I would like to create a column of working day from the event. 

 

Date 

Sedol

event_day

Calday

workday

31/01/1995

4553275

9/02/1995

-9

-7

1/02/1995

4553275

9/02/1995

-8

-6

2/02/1995

4553275

9/02/1995

-7

-5

3/02/1995

4553275

9/02/1995

-6

-4

6/02/1995

4553275

9/02/1995

-3

-3

7/02/1995

4553275

9/02/1995

-2

-2

8/02/1995

4553275

9/02/1995

-1

-1

9/02/1995

4553275

9/02/1995

0

0

10/02/1995

4553275

9/02/1995

1

1

13/02/1995

4553275

9/02/1995

4

2

14/02/1995

4553275

9/02/1995

5

3

15/02/1995

4553275

9/02/1995

6

4

16/02/1995

4553275

9/02/1995

7

5

17/02/1995

4553275

9/02/1995

8

6

20/02/1995

4553275

9/02/1995

11

7

 

How to do that? Can someone please help? Thanks in advance for your help.

2 REPLIES 2
mkeintz
PROC Star

SAS has two excellent functions for dates, times, and datetimes.  INTNX, which you don't need here produces a date from a starting date and an interval size, where the interval could be day, week, month, qtr, hour, etc.

 

You want INTCK, which gets the interval size between two dates.  In your case the interval is not DAY or MONTH, etc.  It is "weekday" (which I presume is what you mean by "work day"):

 

data have;
  input  Date ddmmyy10.   Sedol event_day ddmmyy10. Calday;
  format date event_day date9.;
datalines;
31/01/1995 4553275  9/02/1995 -9
 1/02/1995 4553275  9/02/1995 -8
 2/02/1995 4553275  9/02/1995 -7
 3/02/1995 4553275  9/02/1995 -6
 6/02/1995 4553275  9/02/1995 -3
 7/02/1995 4553275  9/02/1995 -2
 8/02/1995 4553275  9/02/1995 -1
 9/02/1995 4553275  9/02/1995  0
10/02/1995 4553275  9/02/1995  1
13/02/1995 4553275  9/02/1995  4
14/02/1995 4553275  9/02/1995  5
15/02/1995 4553275  9/02/1995  6
16/02/1995 4553275  9/02/1995  7
17/02/1995 4553275  9/02/1995  8
20/02/1995 4553275  9/02/1995 11
run;

data want;
  set have;
  wrkday=intck('weekday',event_day,date);
run;

 

Question:  what do you intend to do about holidays that fall on weekdays?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
PGStats
Opal | Level 21

If workday is the same as weekday :

 

workday = intck("weekday", event_day, date);

PG

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 678 views
  • 0 likes
  • 3 in conversation