Previous Page | Next Page

The SASECRSP Interface Engine

Example 33.11 Using INSET Ranges with the LIBNAME RANGE Option

It is possible to specify both individual range restrictions with an INSET and a global date range restriction via the RANGE= option on the LIBNAME statement. In such cases, only observations that satisfy both date range restrictions are returned. The effective range restriction becomes the intersection of the two specified range restrictions. If this intersection is empty, no observations are returned.

This example extracts data for two companies, IBM and Microsoft. Each company has an individual range restriction specified in the inset. Furthermore, a global range restriction is set by the RANGE= option on the LIBNAME statement. As a result the effective date range restriction for IBM becomes August 1, 1999, to February 1, 2000, and the effective date range restriction for Microsoft becomes January 1, 2001, to April 21, 2002.

   data two_companies;
      gvkey=6066;  date1=19800101; date2=20000201; output;
      gvkey=12141; date1=20010101; date2=20051231; output;
   run;
   
   libname _all_ clear;
   libname mylib sasecrsp "%sysget(CRSP_CST)"
           SETID=200
           INSET='two_companies,gvkey,gvkey,date1,date2'
           RANGE='19990801-20020421';
   
   title1 'Two Companies, Two Range Selections';
   title2 'Global RANGE Statement Used With Individual Inset Ranges';
   title3 'Results Show Intersection of Both Range Restrictions';
   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;

Output 33.11.1 shows the combined effect of both INSET and RANGE date restrictions on the closing prices and earnings per share for IBM and Microsoft.

Output 33.11.1 Mixing INSET Ranges with the RANGE= Option
Two Companies, Two Range Selections
Global RANGE Statement Used With Individual Inset Ranges
Results Show Intersection of Both Range Restrictions

GVKEY Calendar Trading
Date
Closing Price Earnings Per Share
6066 19990831 124.5625 4.1950
6066 19990930 121.0000 4.3650
6066 19991029 98.2500 4.3650
6066 19991130 103.0625 4.3650
6066 19991231 107.8750 4.2500
6066 20000131 112.2500 4.2500
12141 20010131 30.5313 0.9500
12141 20010228 29.5000 0.9500
12141 20010330 27.3438 0.9500
12141 20010430 33.8750 0.9500
12141 20010531 34.5900 0.9500
12141 20010629 36.5000 0.7250
12141 20010731 33.0950 0.7250
12141 20010831 28.5250 0.7250
12141 20010928 25.5850 0.6000
12141 20011031 29.0750 0.6000
12141 20011130 32.1050 0.6000
12141 20011231 33.1250 0.5650
12141 20020131 31.8550 0.5650
12141 20020228 29.1700 0.5650
12141 20020328 30.1550 0.5900

For more about using the SQL procedure, see the chapter on SQL in Base SAS Procedures Guide.

Previous Page | Next Page | Top of Page