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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 553 views
  • 0 likes
  • 3 in conversation