Resources

Converting Dates By Using the CRSP Date Functions

/*----------------------------------------------------------------

                    SAS Sample Library

        Name: crpex06.sas
 Description: Example program from SAS/ETS User's Guide,
              The SASECRSP Interface Engine
    Title: Converting Dates By Using the CRSP Date Functions
  Product: SAS/ETS Software
     Keys: Stock data access, CRSPAccess, CRSP Date Functions
    Procs: SASECRSP
    Notes: Read this before you run this sample.
           The CRSP Stock database resides in the  CRSP_MSTK folder. You
           must install your CRSP Monthly Stock data
           and define your Windows system environment
           variable, CRSP_MSTK, to point to the physical path
           of your installed CRSP Stock database. Use the following
           form of the libname statement:

libname mstk sasecrsp "%sysget(CRSP_MSTK)"
        setid=20;
----------------------------------------------------------------*/

title2 'OUT= Data Set';
title3 'CRSP Functions for sasecrsp';

libname _all_ clear;

/* Always assign the LIBNAME sasecrsp first */
libname mstk sasecrsp "%sysget(CRSP_MSTK)"
        setid=20;

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);
run;

title3 'PROC PRINT showing data for sasecrsp';
proc print data=a;
run;

title3 'PROC CONTENTS showing formats for sasecrsp';
proc contents data=a;
run;