The SASECRSP Interface Engine

Understanding CRSP Date Formats, Informats, and Functions

CRSP has historically used two different methods to represent dates, whereas SAS has used a third. The three formats are SAS dates, CRSP dates, and integer dates. The SASECRSP engine provides 23 functions, 15 informats, and 10 formats to enable you to easily translate the dates from one internal representation to another. A SASECRSP engine libref must be assigned prior to your use of the CRSP date formats, informats, and functions. See Example 46.6, "Converting Dates Using the CRSP Date Functions."

SAS dates are stored internally as the number of days since January 1, 1960. The SAS method is an industry standard that provides a great deal of flexibility, including a wide variety of informats, formats, and functions.

CRSP dates are designed to ease time series storage and access. Internally, the dates are stored as an offset in an array of trading days or a trading-day calendar. There are five different CRSP trading-day calendars: Annual, Quarterly, Monthly, Weekly, and Daily. In this sense, there are five different types of CRSP dates, one for each frequency of calendar that it references. The CRSP method provides fewer missing values and makes trading period calculations very easy. However, many valid calendar dates are not available in the CRSP trading calendars, and you must be careful when you use other dates.

Integer dates are a way to represent dates that are platform-independent and maintain the correct sort order. However, the distance between dates is not maintained.

The best way to illustrate the various date formats is to use some sample data. Table 46.6 shows date representations for CRSP daily and monthly data.

Table 46.6: Date Representations for Daily and Monthly Data

Date

SAS Date

CRSP Date

CRSP Date

Integer Date

   

(Daily)

(Monthly)

 

July 31, 1962

942

21

440

19620731

August 31, 1962

973

44

441

19620831

Dec. 30, 1998

14,243

9190

NA*

19981230

Dec. 31, 1998

14,244

9191

877

19981231

* Not available if an exact match is requested.


Having an understanding of the internal differences in representing SAS dates, CRSP dates, and CRSP integer dates helps you use the SASECRSP engine formats, informats, and functions effectively. Always keep in mind the frequency of the CRSP calendar that you are accessing when you specify a CRSP date.

The CRSP Date Formats

CRSP dates use two types of formats, and five frequencies are available for each type. The two types are exact dates (CRSPDT*) and range dates (CRSPDR*), where the '*' can be A for annual, Q for quarterly, M for monthly, W for weekly, or D for daily. The ten types are CRSPDTA, CRSPDTQ, CRSPDTM, CRSPDTW, CRSPDTD, CRSPDRA, CRSPDRQ, CRSPDRM, CRSPDRW, and CRSPDRD.

Table 46.7 shows some samples that use the monthly and daily calendar as examples. The Annual (CRSPDTA and CRSPDRA), Quarterly (CRSPDTQ and CRSPDRQ), and Weekly (CRSPDTW and CRSPDRW) formats work analogously.

Table 46.7: Sample CRSPDT Formats for Daily and Monthly Data

 

CRSP Date

CRSPDTD

CRSPDRD

CRSPDTM

CRSPDRM

Date

Daily, Monthly

Daily Date

Daily Range

Monthly Date

Monthly Range

July 31,1962

21, 440

19620731

19620731 +

19620731

19620630, 19620731

August 31,1962

44, 441

19620831

19620831 +

19620831

19620801, 19620831

Dec. 30,1998

9190, NA *

19981230

19981230 +

NA*

NA*

Dec. 31,1998

9191, 877

19981231

19981231 +

19981231

19981201, 19981231

+ Daily ranges look similar to monthly ranges if they are Mondays or immediately follow a trading holiday.

* When you are working with exact matches, no CRSP monthly date exists for December 30, 1998.


The @CRSP Date Informats

CRSP dates use three types of informats, and five frequencies are available for each type. The three types are exact (@CRSPDT*), range (@CRSPDR*), and backward (@CRSPDB*) dates, where the '*' can be A for annual, Q for quarterly, M for monthly, W for weekly, or D for daily. The 15 formats are @CRSPDTA, @CRSPDTQ, @CRSPDTM, @CRSPDTW, @CRSPDTD, @CRSPDRA, @CRSPDRQ, @CRSPDRM, @CRSPDRW, @CRSPDRD, @CRSPDBA, @CRSPDBQ, @CRSPDBM, @CRSPDBW, and @CRSPDBD.

The five CRSPDT* informats find exact matches only. The five CRSPDR* informats look for an exact match, and if an exact match is not found, they go forward, matching the CRSPDR* formats. The five CRSPDB* informats look for an exact match, and if an exact match is not found, they go backward.

Table 46.8 shows a sample that uses only the CRSP monthly calendar as an example. The daily, weekly, quarterly, and annual frequencies work analogously.

Table 46.8: Sample @CRSP Date Informats Using Monthly Data

Input Date

CRSP Date

CRSP Date

CRSP Date

CRSPDTM

CRSPDRM

(Integer Date)

CRSPDTM

CRSPDRM

CRSPDBM

Monthly Date

Monthly Range

19620731

440

440

440

19620731

19620630 to 19620731

19620815

.(missing)

441

440

See below+

See below*

19620831

441

441

441

19620831

19620801 to 19620831

+ Missing values are preserved. If 441, then 19620831. If 440, then 19620731.

* Missing values are preserved. If 441, then 19620801 to 19620831. If 440, then 19620630 to 19620731.


The CRSP Date Functions

Table 46.9 shows the 22 date functions that the SASECRSP engine provides. The engine uses these functions internally, but they are also available to end users. There are seven groups of functions. The first four groups have five functions each, one for each CRSP calendar frequency. The next two functions are for converting between SAS and integer date formats.

Table 46.9: CRSP Date Functions

Function

Function

Argument

Argument

Return

Group

Name

One

Two

Value

CRSP dates to integer dates for December 31, 1998

Annual

crspdcia

74

None

19981231

Quarterly

crspdciq

293

None

19981231

Monthly

crspdcim

877

None

19981231

Weekly

crspdciw

1905

None

19981231

Daily

crspdcid

9191

None

19981231

CRSP dates to SAS dates for December 31, 1998

Annual

crspdcsa

74

None

14,244

Quarterly

crspdcsq

293

None

14,244

Monthly

crspdcsm

877

None

14,244

Weekly

crspdcsw

1905

None

14,244

Daily

crspdcsd

9191

None

14,244

Integer dates to CRSP dates exact is illustrated, but can be forward or backward

Annual

crspdica

19981231

0

74

Quarterly

crspdicq

19981231

0

293

Monthly

crspdicm

19981231

0

877

Weekly

crspdicw

19981231

0

1905

Daily

crspdicd

19981231

0

9191

SAS dates to CRSP dates exact is illustrated, but can be forward or backward

Annual

crspdsca

14,244

0

74

Quarterly

crspdscq

14,244

0

293

Monthly

crspdscm

14,244

0

877

Weekly

crspdscw

14,244

0

1905

Daily

crspdscd

14,244

0

9191

Integer dates to SAS dates for December 31, 1998

Integer to SAS

crspdi2s

19981231

None

14,244

SAS dates to integer dates for December 31, 1998

SAS to Integer

crspds2i

14,244

None

19981231