Previous Page | Next Page

The SASECRSP Interface Engine

Using the Inset Option

To better illustrate the use of the INSET= option, some examples follow:

Basic Inset Use: Providing a List of PERMNOs

This example uses the INSET= option to extract monthly data for a portfolio of three companies. No date range restriction is used.

  data testin1;
     permno = 10107; output;
     permno = 12490; output;
     permno = 14322; output;
  run;

  LIBNAME mstk sasecrsp 'physical-name'
                        SETID=20
                        INSET='testin1';

  proc print data=mstk.stkhead (keep=permno permco begdt enddt hcomnam htick);
  run;

General Use of Inset for Specifying Lists of Keys

The following example illustrates the use of the INSET= option to select a few Index Series from the Indices database, companies from the CCM database, and securities from the Stock database. Libref ind2 is used for accessing the Indices database with the two specified INDNOs. Libref comp2 is used to access the CCM database with the two specified PERMCOs. Libref sec3 is used to access the Stock database with the three specified TICKERs. Note the use of shorthand in specifying the INSET= option. The date1field, date2field, and datetype fields are all omitted, thereby using the default of no range restriction (though the range restriction set by the RANGE= on the LIBNAME statement still applies). For details including sample output, see Example 33.4

  data indices;
      indno=1000000; output;  /* NYSE Value-Weighted Market Index */
      indno=1000001; output;  /* NYSE Equal-Weighted Market Index */
  run;

  libname ind2 sasecrsp "%sysget(CRSP_MSTK)" setid=420
      inset='indices,INDNO,INDNO' range='19990101-19990401';

  title2 'Total Returns for NYSE Value and Equal Weighted Market Indices';
  proc print data=ind2.tret label;
  run;

  data companies;
      permco=8045;  output;  /* Oracle */
      permco=20483; output;  /* Citigroup */
  run;

  libname comp2 sasecrsp "%sysget(CRSP_CST)" setid=200
                          inset='companies,PERMCO,PERMCO'
                          range='20040101-20040531';

  title2 'Link Info of Selected PERMCOs';
  proc print data=comp2.link label; run;

  title3 'Dividends Per Share for Oracle and Citigroup';
  proc print data=comp2.div label; run;

  data securities;
      ticker='BAC'; output;  /* Bank of America */
      ticker='DUK'; output;  /* Duke Energy */
      ticker='GSK'; output;  /* GlaxoSmithKline */
  run;

  libname sec3 sasecrsp "%sysget(CRSP_MSTK)" setid=20
                         inset='securities,TICKER,TICKER'
                         range='19970820-19970920';

  title2 'PERMNOs and General Header Info of Selected TICKERs';
  proc print data=sec3.stkhead (keep=permno htick htsymbol) label;
  run;

  title3 'Average Price for Bank of America, Duke and GlaxoSmithKline';
  proc print data=sec3.prc label; run;

Key-Specific Date Range Restriction with Insets

Suppose you not only want to select keys with your inset, but also want to specify a date range restriction for each key individually. The following example shows how to do this. Again, shorthand enables you to omit the datetype field. The provided dates default to a calendar interpretation. For details including the sample output, see Example 33.5.

  title2 'INSET=testin2 uses date ranges along with PERMNOs:';
  title3 '10107, 12490, 14322, 25788';
  title4 'Begin dates and end dates for each permno are used in the INSET';

  data testin2;
      permno = 10107; date1 = 19980731; date2 = 19981231; output;
      permno = 12490; date1 = 19970101; date2 = 19971231; output;
      permno = 14322; date1 = 19950731; date2 = 19960131; output;
      permno = 25778; date1 = 19950101; date2 = 19950331; output;
  run;

  libname mstk2 sasecrsp "%sysget(CRSP_MSTK)" setid=20
                         inset='testin2,PERMNO,PERMNO,DATE1,DATE2';

  data b;
      set mstk2.prc;
  run;

  proc print data=b;
  run;

Fiscal Date Range Restrictions with Insets

You can use fiscal dates on the date range restrictions inside insets by specifying the date type. The following example shows two identical accesses, except one inset uses the date range restriction in fiscal terms, and the other inset uses the date range restriction in calendar terms. For details including sample output, see Example 33.10.

   data comp_fiscal;

      /* Crude Petroleum & Natural Gas */
      compkey=2416;
      begdate=19860101; enddate=19861231;
      datetype='fiscal';
      output;

      /* Commercial Intertech */
      compkey=3248;
      begdate=19940101; enddate=19941231;
      datetype='fiscal';
      output;
   run;

   data comp_calendar;

      /* Crude Petroleum & Natural Gas */
      compkey=2416;
      begdate=19860101; enddate=19861231;
      datetype='calendar';
      output;

      /* Commercial Intertech */
      compkey=3248;
      begdate=19940101; enddate=19941231;
      datetype='calendar';
      output;
   run;

   libname fisclib sasecrsp "%sysget(CRSP_CST)"
           SETID=200
           INSET='comp_fiscal,compkey,gvkey,begdate,enddate,datetype';

   libname callib sasecrsp "%sysget(CRSP_CST)"
           SETID=200
           INSET='comp_calendar,compkey,gvkey,begdate,enddate,datetype';

   title2 'Quarterly Period Descriptors with Fiscal Date Range';
   proc print data=fisclib.qperdes(drop = peftnt1 peftnt2 peftnt3 peftnt4
       peftnt5 peftnt6 peftnt7 peftnt8 candxc flowcd spbond spdebt sppaper);
   run;

   title2 'Quarterly Period Descriptors with Calendar Date Range';
   proc print data=callib.qperdes(drop = peftnt1 peftnt2 peftnt3 peftnt4
       peftnt5 peftnt6 peftnt7 peftnt8 candxc flowcd spbond spdebt sppaper);
   run;

Inset Ranges in Conjunction with the LIBNAME Range

Suppose you want to specify individual date restrictions but also impose a common range. This example demonstrates two companies, each with its own date range restriction, but both companies are also subject to a common range set in the LIBNAME by the RANGE= option. As a result, data from August 1, 1999, to February 1, 2000, is retrieved for IBM, and data from January 1, 2001, to April 21, 2002, is retrieved for Microsoft. For details including sample output see Example 33.11.

   data two_companies;
     gvkey=6066;  date1=19800101; date2=20000201; output;
     gvkey=12141; date1=20010101; date2=20051231; output;
   run;

   libname mylib sasecrsp "%sysget(CRSP_CST)"
           SETID=200
           INSET='two_companies,gvkey,gvkey,date1,date2'
           RANGE='19990801-20020421';

   proc sql;
      select prcc.gvkey,prcc.caldt,prcc,ern
         from mylib.prcc as prcc, mylib.ern as ern
         where prcc.caldt = ern.caldt and
               prcc.gvkey = ern.gvkey;
   quit;
Previous Page | Next Page | Top of Page