Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
The SASECRSP Interface Engine

Example 1.5: Converting Dates 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';
   title4 'Always assign the libname sasecrsp first';

   libname mstk sasecrsp '/mydata/crspeng/m_sampdata/' 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;

   proc print;
      run;

   title2 'Proc CONTENTS showing formats for sasecrsp';
   proc contents data=a;
      run;

Output 1.5.1: Printout of Date Conversions Using the CRSP Date Functions

                                The SAS System                               1
                                OUT= Data Set
                         CRSP Functions for sasecrsp
                   Always assign the libname sasecrsp first

Obs crspdt   crspdt2  crspdt3   sasdt sasdt2 sasdt3    intdt   intdt2   intdt3

 1  19620702 19620702 19620702 620702 620702 620702 19620702 19620702 19620702
                                                                                     
                  Proc CONTENTS showing formats for sasecrsp
                         CRSP Functions for sasecrsp
                   Always assign the libname sasecrsp first

                            The CONTENTS Procedure

Data Set Name: WORK.A                                 Observations:         1 
Member Type:   DATA                                   Variables:            9 
Engine:        V8                                     Indexes:              0 
Created:       13:15 Monday, November 27, 2000        Observation Length:   72
Last Modified: 13:15 Monday, November 27, 2000        Deleted Observations: 0 
Protection:                                           Compressed:           NO
Data Set Type:                                        Sorted:               NO
Label:                                                                        


                 -----Engine/Host Dependent Information-----

       Data Set Page Size:         8192                                
       Number of Data Set Pages:   1                                   
       First Data Page:            1                                   
       Max Obs per Page:           113                                 
       Obs in First Data Page:     1                                   
       Number of Data Set Repairs: 0                                   
       File Name:                  /tmp/SAS_work67560000352F/a.sas7bdat
       Release Created:            8.0202M0                            
       Host Created:               HP-UX                               
       Inode Number:               414                                 
       Access Permission:          rw-r--r--                           
       Owner Name:                 saskff                              
       File Size (bytes):          16384                               


             -----Alphabetic List of Variables and Attributes-----
 
               #    Variable    Type    Len    Pos    Format
               ------------------------------------------------
               1    crspdt      Num       8      0    CRSPDTD8.
               2    crspdt2     Num       8      8    CRSPDTD8.
               3    crspdt3     Num       8     16    CRSPDTD8.
               7    intdt       Num       8     48    8.       
               8    intdt2      Num       8     56    8.       
               9    intdt3      Num       8     64    8.       
               4    sasdt       Num       8     24    YYMMDD6. 
               5    sasdt2      Num       8     32    YYMMDD6. 
               6    sasdt3      Num       8     40    YYMMDD6. 

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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