Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
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 22 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.

SAS dates are internally stored 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. Note that there are five different CRSP trading day calendars: Annual, Quarterly, Monthly, Weekly, and Daily. 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. The table below only shows CRSP Daily and Monthly dates.

Table 1.2: Date Representations for Daily and Monthly Data
Date SAS Date CRSP Date CRSP Date Integer Date
    (Daily) (Monthly)  
July 31, 19629422144019620731
August 31, 19629734444119620831
December 30, 199814,2439190NA*19981230
December 31, 199814,244919187719981231
* 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 will help 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 * can be A for annual, Q for quarterly, M for monthly, W for weekly, or D for daily. The ten formats are: CRSPDTA, CRSPDTQ, CRSPDTM, CRSPDTW, CRSPDTD, CRSPDRA, CRSPDRQ, CRSPDRM, CRSPDRW, and CRSPDRD.

Here are some samples using the monthly and daily calendar as examples. The Annual (CRSPDTA and CRSPDRA), Quarterly (CRSPDTQ and CRSPDRQ), and the Weekly (CRSPDTW and CRSPDRW) work analogously.

Table 1.3: Sample CRSPDT Formats for Daily and Monthly Data
  CRSP Date CRSPDTD8. CRSPDRD8. CRSPDTM8. CRSPDRM8.
Date Daily , Monthly Daily Date Daily Range Monthly Date Monthly Range
July 31,196221 , 4401962073119620731 +1962073119620630-19620731
August31,196244 , 4411962083119620831 +1962083119620801-19620831
December30,9190 , NA *1998123019981230 +NA*NA*
1998     
December31,9191 , 8771998123119981231 +1998123119981201-19981231
1998     
+ Daily ranges will 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 * 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 it is not found it goes forward, matching the CRSPDR* formats. The five CRSPDB* informats look for an exact match, and if it is not found it goes backward. Here is a sample using only the CRSP monthly calendar as an example, but the daily, weekly, quarterly, and annual frequencies work analogously.

Table 1.4: Sample @CRSP Date Informats Using Monthly Data
Input Date CRSP Date CRSP Date CRSP Date CRSPDTM8. CRSPDRM8.
(Integer Date) CRSPDTM CRSPDRM CRSPDBM Monthly Date Monthly Range
196207314404404401962073119620630-19620731
19620815.(missing)441440See below+See below*
196208314414414411962083119620801-19620831
+ If missing, then missing. If 441, then 19620831. If 440, then 19620731.
* If missing, then missing. If 441, then 19620801-19620831. If 440, then 19620630-19620731.

The CRSP Date Functions

There are 22 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 six groups of functions. The first four have five functions each, one for each CRSP calendar frequency.

Table 1.5: CRSP Date Functions
Function Function Argument Argument Return
Group Name One Two Value
CRSP dates to Integer dates for December 31, 1998
Annualcrspdcia74None19981231
Quarterlycrspdciq293None19981231
Monthlycrspdcim877None19981231
Weeklycrspdciw1905None19981231
Dailycrspdcid9191None19981231
CRSP dates to SAS dates for December 31, 1998
Annualcrspdcsa74None14,244
Quarterlycrspdcsq293None14,244
Monthlycrspdcsm877None14,244
Weeklycrspdcsw1905None14,244
Dailycrspdcsd9191None14,244
Integer dates to CRSP dates exact is illustrated, but can be forward or backward
Annualcrspdica19981231074
Quarterlycrspdicq199812310293
Monthlycrspdicm199812310877
Weeklycrspdicw1998123101905
Dailycrspdicd1998123109191
SAS dates to CRSP dates exact is illustrated, but can be forward or backward
Annualcrspdsca14,244074
Quarterlycrspdscq14,2440293
Monthlycrspdscm14,2440877
Weeklycrspdscw14,24401905
Dailycrspdscd14,24409191
Integer dates to SAS dates for December 31, 1998
Integer to SAScrspdi2s19981231None14,244
SAS dates to Integer dates for December 31, 1998
SAS to Integercrspds2i14,244None19981231

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.