Previous Page | Next Page

The SASECRSP Interface Engine

Understanding CRSP Date Formats, Informats, and Functions

CRSP has historically used two different methods to represent dates, while 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 LIBNAME assign must be active to use these date access methods. See Example 35.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 and 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 into an array of trading days or trading day calendar. Note that 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 it references. The CRSP method provides fewer missing values and makes trading period calculations very easy. However, there are also many valid calendar dates that are not available in the CRSP trading calendars, and care must be taken when using 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 these formats is with some sample data. Table 35.8 shows date representations for CRSP daily and monthly data.

Table 35.8 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 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

There are two types of formats for CRSP dates, and five frequencies are available for each of the two types. 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 35.9 shows some samples that use the monthly and daily calendar as examples. The Annual (CRSPDTA and CRSPDRA), Quarterly (CRSPDTQ and CRSPDRQ), and the Weekly (CRSPDTW and CRSPDRW) formats work analogously.

Table 35.9 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 following a trading holiday.

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

The @CRSP Date Informats

There are three types of informats for CRSP dates, and five frequencies are available for each of the three types. 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 fifteen 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 35.10 shows a sample that uses only the CRSP monthly calendar as an example. The daily, weekly, quarterly, and annual frequencies work analogously.

Table 35.10 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

+ If missing, then missing. If 441, then 19620831. If 440, then 19620731.

* If missing, then missing. If 441, then 19620801 to 19620831. If 440, then 19620630 to 19620731.

The CRSP Date Functions

Table 35.11 shows the 23 date functions provided with the SASECRSP engine. These functions are used internally by the engine, but also are available to the end users. There are seven groups of functions. The first four have five functions each, one for each CRSP calendar frequency. The next two are for converting between SAS and Integer date formats. The last function does not convert between formats, but is a shifting function for shifting integer dates based on a fiscal calendar to normal calendar time. In this shift function, the second argument holds the fiscal year-end month of the fiscal calendar used.

Table 35.11 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

Fiscal to calendar shifting of integer dates for December 31, 1998

Fiscal to Calendar Shift

crspdf2c

20021231

8

20020831


Previous Page | Next Page | Top of Page