DATASOURCE Procedure

Example 12.2 BLS Consumer Price Index Surveys

(View the complete code for this example.)

This example compares changes of the prices in medical care services with respect to different regions for all urban consumers (SURVEY=’CU’) since May 1975. The source of the data is the Consumer Price Index Surveys distributed by the U.S. Department of Labor, Bureau of Labor Statistics.

An initial run of PROC DATASOURCE gives the descriptive information on different regions available (the OUTBY= data set), as well as the series variable name corresponding to medical care services (the OUTCONT= data set).

options yearcutoff = 1900;

filename datafile "%sysget(DATASRC_DATA)blscpi1.data" recfm=v lrecl=152;
proc datasource filetype=blscpi
   interval=mon
   outselect=off
   outby=cpikey(where=( upcase(areaname)
                   in ('NORTHEAST','NORTH CENTRAL','SOUTH','WEST')) )
   outcont=cpicont(where= ( index( upcase(label), 'MEDICAL CARE' )) );
   where survey='CU';
run;

title1 'OUTBY= Data Set, By AREANAME Selection';
proc print
   data=cpikey;
run;

title1 'OUTCONT= Data Set, By LABEL Selection';
proc print
   data=cpicont;
run;

The OUTBY= data set in Output 12.2.1 lists all cross sections available for the four geographical regions: Northeast (AREA=’0100’), North Central (AREA=’0200’), Southern (AREA=’0300’), and Western (AREA=’0400’). The OUTCONT= data set in Output 12.2.2 gives the variable names for medical care related series.

Output 12.2.1: Partial Listings of the OUTBY= Data Set

OUTBY= Data Set, By AREANAME Selection

ObsSURVEYSEASONAREABASPTYPEBASEPERBYSELECTST_DATEEND_DATENTIMENOBSNSERIESNSELECTSURTITLEAREANAME
1CUU0200S1982-84=1001DEC1977JUL199015215222ALL URBAN CONSUMNORTH CENTRAL
2CUU0100S1982-84=1001...000ALL URBAN CONSUMNORTHEAST
3CWU0400S1982-84=1000DEC1977JUL1990152010URBAN WAGE EARNWEST
4CWU0100S1982-84=1000...000URBAN WAGE EARNNORTHEAST
5CWU0200S1982-84=1000...000URBAN WAGE EARNNORTH CENTRAL


Output 12.2.2: Partial Listings of the OUTCONT= Data Set

OUTCONT= Data Set, By LABEL Selection

ObsNAMESELECTEDTYPELENGTHVARNUMLABELFORMATFORMATLFORMATD
1ASL5115.SERVICES LESS MEDICAL CARE 00
2A512115.MEDICAL CARE SERVICES 00
3A0L5015.ALL ITEMS LESS MEDICAL CARE 00


The following statements make use of this information to extract the data for A512 and descriptive information on cross sections containing A512. Output 12.2.3 and Output 12.2.4 show these results.

options yearcutoff = 1900;

filename datafile "%sysget(DATASRC_DATA)blscpi1.data" recfm=v lrecl=152;

proc format;
   value $areafmt '0100' = 'Northeast Region'
                  '0200' = 'North Central Region'
                  '0300' = 'Southern Region'
                  '0400' = 'Western Region';
run;

proc datasource filetype=blscpi interval=month
             out=medical outall=medinfo;
   where survey='CU' and area in ( '0100','0200','0300','0400' );
   keep date a512;
   range  from 1988:9;
   format area $areafmt.;
   rename a512=medcare;
run;

title1 'Information on Medical Care Service, OUTALL= Data Set';
proc print
   data=medinfo;
run;

title1 'Medical Care Service By Region, OUT= Data Set';
title2 'Range from September, 1988';
proc print
   data=medical;
run;

Output 12.2.3: Printout of the OUTALL= Data Set

Information on Medical Care Service, OUTALL= Data Set

ObsSURVEYSEASONAREABASPTYPEBASEPERBYSELECTNAMEKEPTSELECTEDTYPELENGTHVARNUMBLKNUMLABELFORMATFORMATLFORMATDST_DATEEND_DATENTIMENOBSNINRANGESURTITLEAREANAMES_CODEUNITSNDEC
1CUUNorth Central RegionS1982-84=1001medcare1115750MEDICAL CARE SERVICES 00DEC1977JUL199015215223ALL URBAN CONSUMNORTH CENTRALCUUR0200SA512 1


Output 12.2.4: Printout of the OUT= Data Set

Medical Care Service By Region, OUT= Data Set
Range from September, 1988

ObsSURVEYSEASONAREABASPTYPEBASEPERDATEmedcare
1CUUNorth Central RegionS1982-84=100SEP19881364
2CUUNorth Central RegionS1982-84=100OCT19881365
3CUUNorth Central RegionS1982-84=100NOV19881368
4CUUNorth Central RegionS1982-84=100DEC19881372
5CUUNorth Central RegionS1982-84=100JAN19891387
6CUUNorth Central RegionS1982-84=100FEB19891399
7CUUNorth Central RegionS1982-84=100MAR19891405
8CUUNorth Central RegionS1982-84=100APR19891413
9CUUNorth Central RegionS1982-84=100MAY19891416
10CUUNorth Central RegionS1982-84=100JUN19891425
11CUUNorth Central RegionS1982-84=100JUL19891439
12CUUNorth Central RegionS1982-84=100AUG19891452
13CUUNorth Central RegionS1982-84=100SEP19891460
14CUUNorth Central RegionS1982-84=100OCT19891473
15CUUNorth Central RegionS1982-84=100NOV19891481
16CUUNorth Central RegionS1982-84=100DEC19891485
17CUUNorth Central RegionS1982-84=100JAN19901500
18CUUNorth Central RegionS1982-84=100FEB19901516
19CUUNorth Central RegionS1982-84=100MAR19901528
20CUUNorth Central RegionS1982-84=100APR19901538
21CUUNorth Central RegionS1982-84=100MAY19901548
22CUUNorth Central RegionS1982-84=100JUN19901557
23CUUNorth Central RegionS1982-84=100JUL19901573


The OUTALL= data set in Output 12.2.3 indicates that data values are stored with one decimal place (see the NDEC variable). Therefore, they need to be rescaled, as follows:

   data medical;
      set medical;
      medcare = medcare * 0.1;
   run;

This example illustrates the following features:

  • Descriptive information needed to write KEEP and WHERE statements can be obtained with an initial run of the DATASOURCE procedure.

  • The OUTCONT= and OUTALL= data sets contain information on how data values are stored, such as the precision, the units, and so on.

  • The OUTCONT= and OUTALL= data sets report the new series names assigned by the RENAME statement, not the old names (see the NAME variable in Output 12.2.3).

  • You can use PROC FORMAT to define formats for series or BY variables to enhance your output. Note that PROC DATASOURCE associates a permanent format, $AREAFMT., with the BY variable AREA. As a result, the formatted values are displayed in the printout of the OUTALL=MEDINFO data set (see Output 12.2.3).

Last updated: June 19, 2025