|
Chapter Contents |
Previous |
Next |
| The DATASOURCE Procedure |
This example reads all the data on a three-volume daily NYSE/AMEX combined character data set. Assume that the following filerefs are assigned to the calendar/indices file and security files comprising this database:
| Fileref | VOLSER | File Type |
| calfile | DXAA1 | calendar/indices file on volume 1 |
| secfile1 | DXAA1 | security file on volume 1 |
| secfile2 | DXAA2 | security file on volume 2 |
| secfile3 | DXAA3 | security file on volume 3 |
The data set CALDATA is created by the following statements to contain the calendar/indices file:
proc datasource filetype=crspdci infile=calfile out=caldata; run;
Here the FILETYPE=CRSPDCI indicates that you are reading a character format (indicated by a C in the 6th position) daily (indicated by a D in the 5th position) calendar/indices file (indicated by an I in the 7th position).
The annual data in security files can be obtained by the following statements:
proc datasource filetype=crspdca
infile=( secfile1 secfile2 secfile3 )
out=annual;
run;
Similarly, the data sets to contain the daily security data (the OUT= data set) and the event data (the OUTEVENT= data set) are obtained by the following statements:
proc datasource filetype=crspdcs
infile=( calfile secfile1 secfile2 secfile3 )
out=periodic index outevent=events;
run;
Note that the FILETYPE= has an S at the 7th position, since you are reading the security files. Also, the INFILE= option first expects the fileref of the calendar/indices file since the dating variable (CALDT) is contained in that file. Following the fileref of calendar/indices file, you give the list of security files in the order you want to read them.
The Output 10.9.1 is generated by the following statements:
title1 'First 5 Observations in the Calendar/Indices File';
proc print data=caldata( obs=5 );
run;
title1 'Last 5 Observations in the Calendar/Indices File';
proc print data=caldata( firstobs=6659 ) noobs;
run;
title1 "Periodic Series for CUSIP='09523220'";
title2 "DATE >= '22dec88'd";
proc print data=periodic;
where cusip='09523220' and date >= '22dec88'd;
run;
title1 "Events for CUSIP='09523220'";
proc print data=events;
where cusip='09523220';
run;
Output 10.9.1: Partial Listing of the Output Data Sets|
|
|
|
|
|
By default, the OUT= data set contains only the periodic data. However, you may also want to include the event-oriented data in the OUT= data set. This is accomplished by listing the event variables together with periodic variables in a KEEP statement. For example, if you want to extract the historical CUSIP (NCUSIP), number of shares outstanding (SHROUT), and dividend cash amount (DIVAMT) together with all the periodic series, use the following statements:
proc datasource filetype=crspdcs
infile=( calfile secfile1 secfile2 secfile3 )
out=both outevent=events;
where cusip='09523220';
keep bidlo askhi prc vol ret sxret bxret ncusip shrout divamt;
run;
proc datasource filetype=crspdcs
infile=( calfile secfile1 )
out=both outevent=events;
where cusip='09523220';
keep bidlo askhi prc vol ret sxret bxret ncusip shrout divamt;
run;
proc datasource filetype=crspdcs
infile=( calfile secfile1 )
out=both2 outevent=events2;
where cusip='09523220';
keep bidlo askhi prc vol ret sxret bxret ncusip shrout divamt;
keepevent ncusip shrflg;
run;
title1 "Printout of the First 4 Observations";
title2 "CUSIP = '09523220'";
proc print data=both noobs;
var cusip date vol ncusip divamt shrout;
where cusip='09523220' and date <= '08may88'd;
run;
title1 "Printout of the Observations centered Around 18jul88";
title2 "CUSIP = '09523220'";
proc print data=both noobs;
var cusip date vol ncusip divamt shrout;
where cusip='09523220' and
date between '14jul88'd and '20jul88'd;
run;
title1 "Printout of the Observations centered Around 30sep88";
title2 "CUSIP = '09523220'";
proc print data=both noobs;
var cusip date vol ncusip divamt shrout;
where cusip='09523220' and
date between '28sep88'd and '04oct88'd;
run;
Output 10.9.2: Including Event Variables in the OUT= Data Set|
|
|
|
|
|
The events occurring on days other than the trading dates are not output to the OUT= data set.
The KEEP statement in the preceding example has no effect on the event variables output to the OUTEVENT= data set. If you want to extract only a subset of event variables, you need to use the KEEPEVENT statement. For example, the following code outputs only NCUSIP and SHROUT to the OUTEVENT= data set for CUSIP='09523220':
proc datasource filetype=crspdxc
infile=( calfile secfile1 secfile2 secfile3 )
outevent=subevts;
where cusip='09523220';
keepevent ncusip shrout;
run;
proc datasource filetype=crspdxc
infile=( calfile secfile1)
outevent=subevts;
where cusip='09523220';
keepevent ncusip shrout;
run;
title1 "NCUSIP and SHROUT for CUSIP='09523220'";
proc print data=subevts noobs;
run;
Output 10.9.3: Listing of the OUTEVENT= Data Set with a KEEPEVENT Statement|
|
|
Chapter Contents |
Previous |
Next |
Top |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.