The SASEBLS Interface Engine

Example 20.1 Retrieving Consumer Price Index (CPI) Data for Multiple Time Series

This example shows how to use multiple time series IDs to retrieve Average Price (AP) data, all Urban Consumers (SU) chained Consumer Price Index (CPI) data, Urban Wage Earners and Clerical Workers (CW) current series data, and all Urban Consumers (CU) current series data from the CPI databases. You can view these data at the following URL:

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

INSERIES is an input SAS data set that lists the time series IDs that you want to read from the CPI database. In this example, this 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, specify the name of the input data set as 'INSERIES'. Next, the length of the series ID is specified as 17 bytes prior to listing each series ID 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= name and placed in the folder that is specified in the SASEBLS LIBNAME statement. The INSET= option specifies the INSERIES for the list of series IDs to be retrieved. The date range of the data starts with 2019, as specified by the STARTYEAR= option. The ENDYEAR= option specifies the last year to include in the range of data to be retrieved. FREQ=MONTH specifies the selection of only the monthly data, and the FORMAT= option specifies that the data are to be retrieved using the JSON format. Output 20.1.1 shows the CPI data that are retrieved.


options validvarname=any;

DATA inseries;
   length seriesid $ 17;
   seriesid = 'CUUR0000SA0'; output; /* CPI-U, US city avg, all items */
   seriesid = 'APU0000704111'; output;/* AP, CPI average price data */
   seriesid = 'APU0000711211'; output;   /* bananas */
   seriesid = 'CWUR0000SA0'; output; /* CPI-W, Wage earners */
   seriesid = 'APU0000702111'; output;   /* bread   */
   seriesid = 'APU0000706111'; output;   /* chicken */
   seriesid = 'SUUR0000SA0'; output; /* C-CPI-U, Chained CPI, all urban consumers*/
   seriesid = 'APU0000708111'; output;   /* eggs    */
   seriesid = 'APU0000709112'; output;   /* milk    */
RUN;

title 'Retrieve Consumer Price Index Data for Multiple Time Series';
libname bls sasebls "%sysget(BLS)"
   USER='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
   SETNAME=CPI
   INSET=inseries
   PAYPATH= "%sysget(BLS)payload"
   STARTYEAR='2019'
   ENDYEAR='2021'
   FREQ=month
   OUTJSON=blsex01
   FORMAT=json;

data myCPI;
   set bls.blsex01 ;
run;
proc contents data=myCPI; run;
proc print data=myCPI; run;

Output 20.1.1: Retrieve Consumer Price Index Data for Multiple Time Series

Retrieve Consumer Price Index Data for Multiple Time Series

ObsyearperiodperiodNameAPU0000702111APU0000704111APU0000706111APU0000708111APU0000709112APU0000711211CUUR0000SA0CWUR0000SA0SUUR0000SA0
12019M01January1.2745.5181.4731.5542.9130.576251.712245.133142.001
22019M02February1.2825.5021.4861.5572.9000.571252.776246.218142.571
32019M03March1.2615.6081.4681.5442.9440.581254.202247.768143.297
42019M04April1.2855.5521.4631.4632.9800.567255.548249.332143.926
52019M05May1.2895.8121.4791.3622.9630.579256.092249.871144.183
62019M06June1.2805.8781.5901.2033.0540.574256.143249.747144.243
72019M07July1.2815.7011.5621.2433.0310.569256.571250.236144.409
82019M08August1.2755.5761.5141.2193.0450.578256.558250.112144.388
92019M09September1.2965.5711.4871.3833.1020.569256.759250.251144.428
102019M10October1.3255.6531.5381.2823.1190.573257.346250.894144.629
112019M11November1.3615.5051.4301.4053.1890.573257.208250.644144.518
122019M12December1.3635.4741.4501.5353.1880.573256.974250.452144.251
132020M01January1.3515.5051.4091.4613.2530.570257.971251.361144.813
142020M02February1.3755.4971.3621.4493.1960.574258.678251.935145.193
152020M03March1.3745.2571.4001.5253.2480.576258.115251.375144.913
162020M04April1.4065.3461.5712.0193.2670.581256.389249.515144.142
172020M05May1.4125.348 1.6403.2100.589256.394249.521144.018
182020M06June1.4745.7721.7471.5543.1980.588257.797251.054144.847
192020M07July1.4855.7761.7121.4013.2550.580259.101252.636145.747
202020M08August1.4955.5591.6091.3283.4060.576259.918253.597146.270
212020M09September1.4925.6191.5421.3533.4480.574260.280254.004146.417
222020M10October1.5035.7221.5801.4083.3800.577260.388254.076146.382
232020M11November1.5155.7541.6391.4503.4250.578260.229253.826146.242
242020M12December1.5385.8311.6211.4813.5350.572260.474254.081146.408
252021M01January1.5465.8311.5951.4663.4680.597261.582255.296147.125
262021M02February1.5375.7781.5831.5973.3680.590263.014256.843147.845
272021M03March1.5265.8521.5431.6253.3480.594264.877258.935148.746
282021M04April1.5106.2151.5151.6203.4470.604267.054261.237149.903
292021M05May1.5116.3461.4861.6253.4970.600269.195263.612151.022
302021M06June1.5106.6701.4741.6423.5570.595271.696266.412152.295
312021M07July1.4916.8571.4351.6423.6270.594273.003267.789152.997
322021M08August1.4677.0961.4721.7093.5600.589273.567268.387153.287
332021M09September1.5807.2201.5041.8353.5850.597274.310269.086153.719
342021M10October1.5267.3171.5231.8213.6630.600276.589271.552154.958
352021M11November1.5477.2651.5831.7183.6710.619277.948273.042155.672
362021M12December1.5327.2111.6061.7883.7430.622278.802273.925156.100


Last updated: September 15, 2022