SASEBLS Interface Engine

Example 23.4 Retrieving Consumer Expenditure Survey (CX) Data

This example shows how to retrieve data from the Consumer Expenditure Survey. You can view these data by using the following URL:

https://www.bls.gov/cex/data.htm

INSERIES is an input SAS data set that lists the IDs of the time series to be retrieved from the Consumer Expenditure (CX) database. In this example, the input SAS data set is named in the INSET=INSERIES option. To create the INSERIES data set, use the DATA step. In the DATA statement, the name of the input data set is specified as 'INSERIES'. Next, the length of the series ID is specified as 32 bytes prior to listing the ID of each series to be accessed. Each time series is listed on its own line, along with the OUTPUT statement. When the series IDs have been listed, the DATA step is ended with a RUN statement. The following SASEBLS LIBNAME statement specifies the libref (BLS), followed by the engine name (SASEBLS) and the physical path where the retrieved BLS data are to be stored. The OUTJSON= option names the file where the JSON data are stored. The output data set is created using the OUTJSON= option and placed in the folder that is specified in the SASEBLS LIBNAME statement. The INSET= option specifies the INSERIES data set for the list of series to retrieve using their IDs. In this example, only one time series, CXUCHGASLILB0101M, is requested. The date range of the data starts with 2010, as specified by the STARTYEAR= option. The ENDYEAR= option specifies the last year, 2020, to include in the range of data to retrieve. The FREQ=ANNUAL option specifies the selection of yearly data, but because the CALCULATIONS=TRUE option is specified, the retrieved data also include the net change and percentage change calculation statistics. In this example, only the 12-month net change, CXUCHGASLILB0101M_12, and the 12-month percentage change, CXUCHGASLILB0101M%12, statistics are available. The 1-month net change, 3-month net change, and 6-month net change are missing (not available). In addition, the 1-month percentage change, 3-month percentage change, and 6-month percentage change are also missing (not available). The FORMAT= option specifies that the data are to be retrieved using the JSON format. Output 23.4.1 shows the data that are retrieved.


options validvarname=any;

DATA inseries;
   length seriesid $ 32;
   seriesid = 'CXUCHGASLILB0101M'; output;
RUN;

title 'Retrieve Consumer Expenditure Survey Annual Data';
libname bls sasebls "%sysget(BLS)"
   USER='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
   SETNAME=CEX
   INSET=inseries
   PAYPATH= "%sysget(BLS)payload"
   OUTJSON=blsex04
   STARTYEAR='2010'
   ENDYEAR='2020'
   FREQ=Annual
   CALCULATIONS=true
   CATALOG=true
   FORMAT=json;

data myCEX;
   set bls.blsex04 ;
run;
proc contents data=myCEX; run;
proc print data=myCEX; run;

Output 23.4.1: Net Change in Total Assets and Liabilities by Income Quintiles: All Consumer Units

Retrieve Consumer Expenditure Survey Annual Data

ObsyearperiodperiodNameCXUCHGASLILB0101MCXUCHGASLILB0101M_12CXUCHGASLILB0101M%12
12010A01Annual-4458958-17.7
22011A01Annual-18262632-59.0
32012A01Annual-5092-3266178.9
42013A01Annual1140416496-324.0
52014A01Annual7431-3973-34.8
62015A01Annual6937-494-6.6
72016A01Annual8721178425.7
82017A01Annual14049532861.1
92018A01Annual12679-1370-9.8
102019A01Annual10971-1708-13.5
112020A01Annual3584-7387-67.3


Last updated: November 24, 2025