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;
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 |
| Obs | year | period | periodName | APU0000702111 | APU0000704111 | APU0000706111 | APU0000708111 | APU0000709112 | APU0000711211 | CUUR0000SA0 | CWUR0000SA0 | SUUR0000SA0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2019 | M01 | January | 1.274 | 5.518 | 1.473 | 1.554 | 2.913 | 0.576 | 251.712 | 245.133 | 142.001 |
| 2 | 2019 | M02 | February | 1.282 | 5.502 | 1.486 | 1.557 | 2.900 | 0.571 | 252.776 | 246.218 | 142.571 |
| 3 | 2019 | M03 | March | 1.261 | 5.608 | 1.468 | 1.544 | 2.944 | 0.581 | 254.202 | 247.768 | 143.297 |
| 4 | 2019 | M04 | April | 1.285 | 5.552 | 1.463 | 1.463 | 2.980 | 0.567 | 255.548 | 249.332 | 143.926 |
| 5 | 2019 | M05 | May | 1.289 | 5.812 | 1.479 | 1.362 | 2.963 | 0.579 | 256.092 | 249.871 | 144.183 |
| 6 | 2019 | M06 | June | 1.280 | 5.878 | 1.590 | 1.203 | 3.054 | 0.574 | 256.143 | 249.747 | 144.243 |
| 7 | 2019 | M07 | July | 1.281 | 5.701 | 1.562 | 1.243 | 3.031 | 0.569 | 256.571 | 250.236 | 144.409 |
| 8 | 2019 | M08 | August | 1.275 | 5.576 | 1.514 | 1.219 | 3.045 | 0.578 | 256.558 | 250.112 | 144.388 |
| 9 | 2019 | M09 | September | 1.296 | 5.571 | 1.487 | 1.383 | 3.102 | 0.569 | 256.759 | 250.251 | 144.428 |
| 10 | 2019 | M10 | October | 1.325 | 5.653 | 1.538 | 1.282 | 3.119 | 0.573 | 257.346 | 250.894 | 144.629 |
| 11 | 2019 | M11 | November | 1.361 | 5.505 | 1.430 | 1.405 | 3.189 | 0.573 | 257.208 | 250.644 | 144.518 |
| 12 | 2019 | M12 | December | 1.363 | 5.474 | 1.450 | 1.535 | 3.188 | 0.573 | 256.974 | 250.452 | 144.251 |
| 13 | 2020 | M01 | January | 1.351 | 5.505 | 1.409 | 1.461 | 3.253 | 0.570 | 257.971 | 251.361 | 144.813 |
| 14 | 2020 | M02 | February | 1.375 | 5.497 | 1.362 | 1.449 | 3.196 | 0.574 | 258.678 | 251.935 | 145.193 |
| 15 | 2020 | M03 | March | 1.374 | 5.257 | 1.400 | 1.525 | 3.248 | 0.576 | 258.115 | 251.375 | 144.913 |
| 16 | 2020 | M04 | April | 1.406 | 5.346 | 1.571 | 2.019 | 3.267 | 0.581 | 256.389 | 249.515 | 144.142 |
| 17 | 2020 | M05 | May | 1.412 | 5.348 | 1.640 | 3.210 | 0.589 | 256.394 | 249.521 | 144.018 | |
| 18 | 2020 | M06 | June | 1.474 | 5.772 | 1.747 | 1.554 | 3.198 | 0.588 | 257.797 | 251.054 | 144.847 |
| 19 | 2020 | M07 | July | 1.485 | 5.776 | 1.712 | 1.401 | 3.255 | 0.580 | 259.101 | 252.636 | 145.747 |
| 20 | 2020 | M08 | August | 1.495 | 5.559 | 1.609 | 1.328 | 3.406 | 0.576 | 259.918 | 253.597 | 146.270 |
| 21 | 2020 | M09 | September | 1.492 | 5.619 | 1.542 | 1.353 | 3.448 | 0.574 | 260.280 | 254.004 | 146.417 |
| 22 | 2020 | M10 | October | 1.503 | 5.722 | 1.580 | 1.408 | 3.380 | 0.577 | 260.388 | 254.076 | 146.382 |
| 23 | 2020 | M11 | November | 1.515 | 5.754 | 1.639 | 1.450 | 3.425 | 0.578 | 260.229 | 253.826 | 146.242 |
| 24 | 2020 | M12 | December | 1.538 | 5.831 | 1.621 | 1.481 | 3.535 | 0.572 | 260.474 | 254.081 | 146.408 |
| 25 | 2021 | M01 | January | 1.546 | 5.831 | 1.595 | 1.466 | 3.468 | 0.597 | 261.582 | 255.296 | 147.125 |
| 26 | 2021 | M02 | February | 1.537 | 5.778 | 1.583 | 1.597 | 3.368 | 0.590 | 263.014 | 256.843 | 147.845 |
| 27 | 2021 | M03 | March | 1.526 | 5.852 | 1.543 | 1.625 | 3.348 | 0.594 | 264.877 | 258.935 | 148.746 |
| 28 | 2021 | M04 | April | 1.510 | 6.215 | 1.515 | 1.620 | 3.447 | 0.604 | 267.054 | 261.237 | 149.903 |
| 29 | 2021 | M05 | May | 1.511 | 6.346 | 1.486 | 1.625 | 3.497 | 0.600 | 269.195 | 263.612 | 151.022 |
| 30 | 2021 | M06 | June | 1.510 | 6.670 | 1.474 | 1.642 | 3.557 | 0.595 | 271.696 | 266.412 | 152.295 |
| 31 | 2021 | M07 | July | 1.491 | 6.857 | 1.435 | 1.642 | 3.627 | 0.594 | 273.003 | 267.789 | 152.997 |
| 32 | 2021 | M08 | August | 1.467 | 7.096 | 1.472 | 1.709 | 3.560 | 0.589 | 273.567 | 268.387 | 153.287 |
| 33 | 2021 | M09 | September | 1.580 | 7.220 | 1.504 | 1.835 | 3.585 | 0.597 | 274.310 | 269.086 | 153.719 |
| 34 | 2021 | M10 | October | 1.526 | 7.317 | 1.523 | 1.821 | 3.663 | 0.600 | 276.589 | 271.552 | 154.958 |
| 35 | 2021 | M11 | November | 1.547 | 7.265 | 1.583 | 1.718 | 3.671 | 0.619 | 277.948 | 273.042 | 155.672 |
| 36 | 2021 | M12 | December | 1.532 | 7.211 | 1.606 | 1.788 | 3.743 | 0.622 | 278.802 | 273.925 | 156.100 |