Previous Page | Next Page

The SASECRSP Interface Engine

Example 33.6 Converting Dates By Using the CRSP Date Functions

This example shows how to use the CRSP date functions and formats. The CRSPDTD formats are used for all the crspdt variables, while the YYMMDD format is used for the sasdt variables.

   title2 'OUT= Data Set';
   title3 'CRSP Functions for sasecrsp';
   libname _all_ clear;
   /* Always assign the LIBNAME sasecrsp first */
   libname mstk sasecrsp "%sysget(CRSP_MSTK)"
   data a (keep = crspdt crspdt2 crspdt3
                  sasdt sasdt2 sasdt3
                  intdt intdt2 intdt3);
      format crspdt crspdt2 crspdt3 crspdtd8.;
      format sasdt sasdt2 sasdt3 yymmdd6.;
      format intdt intdt2 intdt3 8.;
      format exact 2.;
      crspdt = 1;
      sasdt = '2jul1962'd;
      intdt = 19620702;
      exact = 0;
   /* Call the CRSP date to Integer function*/
      intdt2 = crspdcid(crspdt);
   /* Call the SAS date to Integer function*/
      intdt3 = crspds2i(sasdt);
   /* Call the Integer to Crsp date function*/
      crspdt2 = crspdicd(intdt,exact);
   /* Call the Sas date to Crsp date conversion function*/
      crspdt3 = crspdscd(sasdt,exact);
   /* Call the CRSP date to SAS date conversion function*/
      sasdt2 = crspdcsd(crspdt);
   /* Call the Integer to Sas date conversion function*/
      sasdt3 = crspdi2s(intdt);
   title3 'PROC PRINT showing data for sasecrsp';
   proc print data=a;
   title3 'PROC CONTENTS showing formats for sasecrsp';
   proc contents data=a;

Output 33.6.1 shows the OUT= data set created by the DATA step.

Output 33.6.1 Date Conversions By Using the CRSP Date Functions
OUT= Data Set
PROC CONTENTS showing formats for sasecrsp

Obs crspdt crspdt2 crspdt3 sasdt sasdt2 sasdt3 intdt intdt2 intdt3
1 19251231 19620702 19620702 620702 251231 620702 19620702 19251231 19620702

Output 33.6.2 shows the contents of the OUT= data set by alphabetically listing the variables and their attributes.

Output 33.6.2 Contents of Date Conversions By Using the CRSP Date Functions
Alphabetic List of Variables and Attributes
# Variable Type Len Format
1 crspdt Num 8 CRSPDTD8.
2 crspdt2 Num 8 CRSPDTD8.
3 crspdt3 Num 8 CRSPDTD8.
7 intdt Num 8 8.
8 intdt2 Num 8 8.
9 intdt3 Num 8 8.
4 sasdt Num 8 YYMMDD6.
5 sasdt2 Num 8 YYMMDD6.
6 sasdt3 Num 8 YYMMDD6.

Previous Page | Next Page | Top of Page