Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
The DATASOURCE Procedure

Selecting Time Series Variables -- The KEEP and DROP Statements

If you want to include specific series in the OUT= data set, list them in a KEEP statement. If, on the other hand, you want to exclude some variables from the OUT= data set, list them in a DROP statement. For example, the following statements extract monthly foreign exchange rates for Japan (EXRJAN), Switzerland (EXRSW), and the United Kingdom (EXRUK) from a DRIBASIC file CITIFILE:

   proc datasource filetype=dribasic infile=citifile
                   interval=month  out=dataset;
      keep  exrjan exrsw exruk;
   run;

The KEEP statement also allows input names to be quoted strings. If the name of a series in the input file contains blanks or special characters that are not valid SAS name syntax, put the series name in quotes to select it. Another way to allow the use of special characters in your SAS variable names, is to use the SAS options statement to designate VALIDVARNAME= ANY. This option will allow PROC DATASOURCE to include special characters in your SAS variable names. The following is an example of extracting series from a FAME database using the DATASOURCE procedure.

   proc datasource filetype=fame dbname='fame_nys /disk1/prc/prc'
                   interval=weekday out=outds outcont=attrds;
      range '1jan90'd to '1feb90'd;
      keep cci.close
           '{ibm.high,ibm.low,ibm.close}'
           'mave(ibm.close,30)'
           'crosslist({gm,f,c},{volume})'
           'cci.close+ibm.close';
      rename 'mave(ibm.close,30)' = ibm30day
             'cci.close+ibm.close' = cci_ibm;
   run;

The resulting output data set OUTDS contains the following series: DATE, CCI_CLOS, IBM_HIGH, IBM_LOW, IBM_CLOS, IBM30DAY, GM_VOLUM, F_VOLUME, C_VOLUME, CCI_IBM.

Obviously, to be able to use KEEP and DROP statements, you need to know the name of time series variables available in the data file. The OUTCONT= option gives you this information. More specifically, the OUTCONT= option creates a data set containing descriptive information on the same frequency time series. This descriptive information includes series names, a flag indicating if the series is selected for output, series variable types, lengths, position of series in the OUT= data set, labels, format names, format lengths, format decimals, and a set of FILETYPE= specific descriptor variables. For example, the following statements list some of the monthly series available in the CITIFILE:

   filename citifile 'host-specific-file-name' <host-options>;
   proc datasource filetype=dribasic infile=citifile
                   interval=month  outcont=vars;
   run;
   
   title1 'Some Time Series Variables Available in CITIFILE';
   proc print data=vars noobs;
   run;

Some Time Series Variables Available in CITIFILE

name selected type length varnum label descript format formatl formatd code
EXRJAN 1 1 5 . FOREIGN EXCHANGE RATE: JAPAN (YEN PER U. FOREIGN EXCHANGE RATE: JAPAN (YEN PER U.S.$)   0 0 EXRJAN
EXRSW 1 1 5 . FOREIGN EXCHANGE RATE: SWITZERLAND (SWIS FOREIGN EXCHANGE RATE: SWITZERLAND (SWISS FRANC PER U.S.$)   0 0 EXRSW
EXRUK 1 1 5 . FOREIGN EXCHANGE RATE: UNITED KINGDOM (C FOREIGN EXCHANGE RATE: UNITED KINGDOM (CENTS PER POUND)   0 0 EXRUK

Figure 10.2: Partial Listing of the OUTCONT= Data Set

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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