The DATASOURCE Procedure

Example 12.7 Quarterly COMPUSTAT Data Files

(View the complete code for this example.)

This example shows how to extract data from a 48-quarter Compustat Database File. For COMPUSTAT data files, the series variable names are constructed by concatenating the name of the data array DATA and the column number containing the required information. For example, for quarterly files the common stock data is in column 56. Therefore, the variable name for this series is DATA56. Similarly, the series variable names for quarterly footnotes are constructed by adding the column number to the array name, QFTNT. For example, the variable name for common stock footnotes is QFTNT14 since the 14th column of the QFTNT array contains this information.

The following example extracts common stock series (DATA56) and its footnote (QFTNT14) for companies whose stocks are traded over-the-counter and not in the S&P 500 Index (ZLIST=06) and whose data reside in the over-the-counter file (FILE=06):

filename compstat "%sysget(DATASRC_DATA)csqibm.dat" recfm=s370v
   lrecl=4820 blksize=14476;
proc datasource filetype=cs48qibm  infile=compstat
                out=stocks outby=company;
   keep data56 qftnt14;
   rename data56=comstock  qftnt14=ftcomstk;
   label  data56='Common Stock'
          qftnt14='Footnote for Common Stock';
   range  from 1990:4;

run;

/*- add company name to the out= data set    */
data stocks;
   merge stocks company( keep=dnum cnum cic coname );
   by dnum cnum cic;
run;

title1 'Common Stocks for Last Quarter of 1990';
proc print data=stocks ;
run;

Output 12.7.1 contains a listing of the STOCKS data set.

Output 12.7.1: Listing of the OUT=STOCKS Data Set

Common Stocks for Last Quarter of 1990

ObsDNUMCNUMCICFILEEINSTKSMBLZLISTXRELFICINCORPSTATECOUNTYDATEcomstockftcomstkCONAME
12670293308102656-04814570ENGH60010131211990:416.2510 ENGRAPH INC
22835372917104606-10471630GENZ6001025171990:40.1620 GENZYME CORP
33564896726106625-09227530TRON60042371051990:43.1380 TRION INC
43576172755100677-00248180CRUS60066851990:4. CIRRUS LOGIC INC
53577602191108611-26930620MILT60010361031990:4. MILTOPE GROUP INC
63630616350104634-02996000MORF6003939351990:4. MOR-FLO INDS
73674827079203694-15278680SILI600106851990:4. SILICONIX INC
83842602720104625-06687800MNES600424231990:46.7540 MINE SAFETY APPLIANCES CO
95080007698103659-10018220AESM6001212251990:4. AERO SYSTEMS INC
105122090324104684-06016620BIND6001818971990:43.2660 BINDLEY WESTERN INDS
115211977865104638-17467520WLHN60026261451990:46.4800 WOLOHAN LUMBER CO
125600299155101636-10508700EVAN6001017311990:4. EVANS INC
135731382091106694-23661770GGUY60066751990:40.0520 GOOD GUYS INC
14737245812M104694-26581530INTS60066851990:4. INTEGRATED SYSTEMS INC
157372566140109604-27115800MCAM6002525171990:40.0770 MARCAM CORPORATION
167373913077103681-04228940TOTE60010301111990:40.0570 UNITED TOTE INC
177510008450108634-10505820AGNC6001039351990:4. AGENCY RENT-A-CAR INC
187819026038307623-23592770AFTI6001042451990:40.0210 AMERICAN FILM TECHNOL
198700055383103659-17812570BEIH60010131211990:40.5170 BEI HOLDINGS LTD
208731759916109604-27293860RGEN6001025171990:4. REPLIGEN CORP


Note that quarterly Compustat data are also available in Universal Character format. If you have this type of file instead of IBM 360/370 General format, use the FILETYPE=CS48QUC option instead.

Last updated: December 20, 2021