SASEUSCB Interface Engine
Getting Started: SASEUSCB Interface Engine
You can query the US Census Bureau (USCB) databases to retrieve the observations or data values for a list of economic time series by specifying the series ID of each time series that you want to read into SAS and by specifying your unique USCB API key. To obtain your own unique API key, start by visiting the USCB website:
https://www.census.gov/data/developers.html
Then click on the Request a Key box at the lower left of that page. Alternatively, you can go directly to the following site:
https://api.census.gov/data/key_signup.html
The USCB API key is a 40-character alphanumeric lowercase string, such as ‘abcdefghijklmnopqrstuvwxyz12345612345678’, and is represented by ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’ in the USER= option in the following example. In addition, the example URLs in this section and in the section Details: SASEUSCB Interface Engine use the same USCB API key as the argument your_uscb_apikey.
Now that you are informed about the terms of service of the USCB data, you can use your USCB API registration key to access the USCB data, as shown in the example that follows.
The following statements enable you to access monthly time series from the EITS (Economic Indicator Time Series) ADVM3 (Advanced Report on Durable Goods) database. The time series for defense aircraft and parts (CATEGORY=DAP) that are selected from the time period starting September 2012 (STARTDATE=’2012-09’) and ending April 2013 (ENDDATE=’2013-04’) are retrieved by using the following SAS DATA step and shown in Figure 1:
options;
title 'Retrieve Monthly Data from EITS ADVM3 (Advanced Report on Durable Goods)';
libname _all_ clear;
libname uscb saseuscb "%sysget(USCB)"
user='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
setname=eits_advm3
for='us:*'
category=DAP
startdate='2012-09'
enddate='2013-04'
outjson=ADVM3
format=json;
data my_gsa;
set uscb.ADVM3 ;
run;
proc contents data=my_gsa; run;
proc print data=my_gsa; run;
Figure 1: Advanced Report on Durable Goods Time Series: my_gsa
| Retrieve Monthly Data from EITS ADVM3 (Advanced Report on Durable Goods) |
| Obs | date | DAP_MPCNO_S | DAP_MPCTI_S | DAP_MPCUO_S | DAP_MPCVS_S | DAP_NO_S | DAP_TI_S | DAP_UO_S | DAP_VS_S | DAP_MPCNO_U | DAP_MPCTI_U | DAP_MPCUO_U | DAP_MPCVS_U | DAP_NO_U | DAP_TI_U | DAP_UO_U | DAP_VS_U |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2012-09 | 31.3 | -3.1 | 1.9 | 3.8 | 6234 | 12637 | 70626 | 4891 | 99.9 | -3.5 | 2.5 | 15.2 | 7177 | 12641 | 69404 | 5470 |
| 2 | 2012-10 | -7.7 | -0.4 | 1.6 | -5.0 | 5752 | 12587 | 71733 | 4645 | -20.7 | -0.2 | 1.9 | -19.9 | 5688 | 12610 | 70711 | 4381 |
| 3 | 2012-11 | -2.5 | 2.6 | 0.9 | 7.1 | 5607 | 12909 | 72367 | 4973 | -2.0 | 2.4 | 0.7 | 15.9 | 5576 | 12909 | 71209 | 5078 |
| 4 | 2012-12 | 50.9 | 0.8 | 4.4 | 5.9 | 8462 | 13009 | 75561 | 5268 | 102.8 | -0.6 | 7.2 | 21.5 | 11306 | 12829 | 76345 | 6170 |
| 5 | 2013-01 | -46.1 | -1.4 | 0.1 | -15.3 | 4561 | 12830 | 75662 | 4460 | -59.4 | -0.4 | 1.5 | -43.6 | 4591 | 12782 | 77457 | 3479 |
| 6 | 2013-02 | -8.0 | 4.1 | -1.0 | 10.8 | 4195 | 13354 | 74915 | 4942 | -28.5 | 4.7 | -1.4 | 24.9 | 3282 | 13389 | 76393 | 4346 |
| 7 | 2013-03 | -15.7 | -2.0 | -2.0 | 2.4 | 3535 | 13086 | 73391 | 5059 | 32.1 | -2.5 | -2.4 | 42.2 | 4334 | 13049 | 74547 | 6180 |
| 8 | 2013-04 | 38.2 | -1.7 | 0.1 | -4.2 | 4886 | 12861 | 73432 | 4845 | -16.3 | -1.4 | -0.8 | -32.1 | 3629 | 12861 | 73980 | 4196 |
The JSON data that the USCB website returns are placed in a file that is named by the OUTJSON= option—in this case, ADVM3.json. Note that the JSON file extension is excluded from the file name that is specified in the OUTJSON= option. When the SET statement is executed, the JSON data are read into a SAS data set named ADVM3.sas7bdat, which resides in the location that is specified inside the string enclosed in double quotation marks in the SASEUSCB LIBNAME statement. So, in the preceding example, if the USCB environment variable is set to /sasusr/uscb/test/, then the SAS data set that is created by reading the downloaded JSON file is placed in the following file: /sasusr/uscb/test/ADVM3.sas7bdat.
An equivalent LIBNAME statement that does not use any environment variables could be as follows:
libname uscb saseuscb "/sasusr/uscb/test/"
user='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
setname=eits_advm3
for='us:*'
category=DAP
startdate='2012-09'
enddate='2013-04'
outjson=ADVM3
format=json;
You could also use either a SAS macro variable or a system environment variable to store the value of your USCB API registration key so that the key does not appear explicitly in your SAS code. The SETNAME= option names the USCB data set that you are retrieving data from.
The result, MY_GSA, is named in the DATA step and shown in Figure 1. It is more efficient to use the DATA step to store your USCB data in a SAS data set and then refer to the SAS data set directly in your PROC PRINT or PROC SGPLOT statement, but you can also refer to the SASEUSCB libref directly, as in the following statement:
proc print data=uscb.ADVM3; run;
The PROC PRINT statement uses the member name, ADVM3; this usage corresponds to specifying the OUTJSON=ADVM3 option. Although using this statement might seem easier, it is not as efficient, because every time you use the SASEUSCB libref, the USCB interface engine reads the entire JSON file into SAS again. It is better to refer to the SAS data set repeatedly than to invoke the interface engine repeatedly. For another example that uses more SASEUSCB LIBNAME statement options, see the section Details: SASEUSCB Interface Engine.
The variable name for each ADVM3 time series is made up of three parts, separated by underscores ('_'): the category code, the data type code, and an 'S' for seasonal data or a 'U' for nonseasonal data. See Table 7 and Table 8 for the complete list of categories and data type codes, respectively, in the ADVM3 data set.