How to access Federal Reserve Economic Data (FRED) with SASEFRED in SAS/ETS® software

2
Photo by AbsolutVision on Unsplash

As a SAS user for most of my professional career and SAS employee for eight years, I thought I had a pretty good idea of what SAS offers and how SAS® Analytics can solve problems. Yet even I can experience an "aha" moment when I learn something new about SAS and I wish I had known before.

My most recent "aha" moment came a few months ago, right as the Covid-19 pandemic started to unfold. I learned about the SASEFRED interface engine, a component of SAS/ETS® software that allows you to retrieve a wide range of economic and financial data from the Federal Reserve Economic Data (FRED) site. Hosted by the Federal Reserve Bank of St. Louis, FRED is a treasure trove of about 765,000 US and international times series data reported at the national, state and county levels.

Being able to retrieve data from FRED directly into SAS has been extremely handy as I've developed interactive dashboards to capture key economic and financial indicators, such as unemployment claims, confidence sentiment, stock market index, volatility, etc. My SAS US Public Sector team's focus on this is part of a bigger effort to come alongside customers since the pandemic began. Our goal is to help all levels of government quickly set up analytical environments and provide timely situational awareness and analytical services. We're glad we're positioned to help public officials address public health and economic consequences of the pandemic.

How to get FRED data

SAS FRED documentation is self-explanatory. The first step is to obtain a unique FRED API key on the FRED site: https://api.stlouisfed.org/api_key.html. Once that’s done, you are off to the race.

Below is the snippet of the code that I used to pull unemployment data into SAS with SASEFRED.

options validvarname=any
   sslcalistloc="/opt/sas/viya/config/etc/SASSecurityCertificateFramework/cacerts/trustedcerts.pem";
 
libname _all_ clear;
libname mylib "/opt/sas/viya/config/data/cas/default/public"; /** Folder for final datasets **/
/** Ingest FRED Data **/
 
libname fred sasefred "/opt/sas/viya/config/data/cas/default/public/fred"
   OUTXML=UnemploymentClaims
   AUTOMAP=replace
   APIKEY='XXXXXXXXXXXXXXXXXXXX'  /** please request your API at this site https://api.stlouisfed.org/api_key.html **/
   IDLIST='ICSA,ICNSA,IC4WSA,CCSA,CCNSA'
   START='2008-01-01'
   END='2020-06-30'
   freq='w'
   ;
data mylib.UnemploymentClaims;
   set fred.UnemploymentClaims;
run;
proc print data=mylib.UnemploymentClaims;
run;

The output of the above code execution is the table ‘UnemploymentClaims’ with information on weekly reported initial unemployment claims, four-week moving average claims, and continued claims (see Figure 1 below).

Figure 1

An interactive dashboard with FRED data

The work was done on SAS® Viya, the next generation of SAS Analytics. SAS Viya offers a wide range of robust analytical capabilities, including visual data exploration and reporting. With data ingested into SAS Viya, I am now able to quickly develop an interactive economic dashboard with relevant indicators that will automatically update as the new economic data is reported – all thanks to SASEFRED (see image below).

Check the resources below to learn more. Hope you found this post relevant and useful. Feel free to reach out if you have any questions!

READ THE PAPER | Using SAS® Forecast Server and the SASEFRED Engine to Enhance Your Forecast WATCH THE VIDEO | Extracting a Common Time Trend in SAS/ETS
Tags learn sas
Share

About Author

Elena Shtern

Customer Advisor Lead

Elena Shtern is a Customer Advisor Lead for Federal Financial Regulators with SAS Public Sector. Her favorite part of her job is to build trust with her customers and provide strategic and tactical advice. Prior to joining SAS, Elena was a manager with PricewaterhouseCoopers LLC and was a Principal Economist on CoreLogic's R&D team. Throughout her career, Elena has used SAS technology extensively on a wide range of analytical projects, such as risk modeling, economic analysis, fraud analytics, litigation consulting, etc. Elena presented at two SAS Global User Forums and has an MBA degree with concentration in Finance from R.H. Smith School of Business, University of Maryland.

2 Comments

  1. Elena Shtern on

    Hello Pat,

    Thank you for reaching out. My work was done on the SAS Viya platform. If you are running this code on SAS 9.4, the syntax could be different.

    I suggest you open a ticket with SAS Technical Support. It has been a few years since I wrote the code. Some other changes may have been made with SAS API to FRED.

  2. Dear Ms. Shtern, I am trying to import FRED data using your example and others, with no success. In running your program I get errors related to unrecognized names and library-related errors. Below is the log along with information about the software program. I have also x'ed out the API key.

    Any help you can provide would be greatly appreciated. Thanks!

    NOTE: Copyright (c) 2016 by SAS Institute Inc., Cary, NC, USA.
    NOTE: SAS (r) Proprietary Software 9.4 (TS1M5)
    Licensed to BD OF REGENTS OF UNIV SYST OF GEORGIA - SFA T&R, Site 70080521.
    NOTE: This session is executing on the X64_10PRO platform.

    NOTE: Updated analytical products:

    SAS/STAT 14.3
    SAS/ETS 14.3
    SAS/IML 14.3
    SAS/QC 14.3

    NOTE: Additional host information:

    X64_10PRO WIN 10.0.19041 Workstation

    NOTE: SAS initialization used:
    real time 1.08 seconds
    cpu time 0.87 seconds

    1 options validvarname=any
    2 sslcalistloc="/opt/sas/viya/config/etc/SASSecurityCertificateFramework/cacerts/trustedcert
    ------------
    13
    2 ! s.pem";
    ERROR 13-12: Unrecognized SAS option name SSLCALISTLOC.

    3
    4 libname _all_ clear;
    5 libname mylib "/opt/sas/viya/config/data/cas/default/public";
    NOTE: Library MYLIB does not exist.
    5 ! /** Folder for final datasets
    5 ! **/
    6 /** Ingest FRED Data **/
    7
    8 libname fred sasefred "/opt/sas/viya/config/data/cas/default/public/fred"
    9 OUTXML=UnemploymentClaims
    10 AUTOMAP=replace
    11 APIKEY='xxxxxxxxxxxxxxxxxxxxxxx' /** please request your API at this site
    11 ! https://api.stlouisfed.org/api_key.html **/
    12 IDLIST='ICSA,ICNSA,IC4WSA,CCSA,CCNSA'
    13 START='2008-01-01'
    14 END='2020-06-30'
    15 freq='w'
    16 ;
    NOTE: The SASEFRED engine uses the FRED API but is not endorsed or certified by the Federal
    Reserve Bank of St. Louis.
    WARNING: By using the SASEFRED interface, you are agreeing to comply with the FRED terms of use:
    https://api.stlouisfed.org/terms_of_use.html. You are also solely responsible for
    obtaining copyright permission before downloading any copyright protected data series.
    To obtain a list of the copyright protected data series, you can visit the following URL
    (substitute your unique FRED api_key in the link):
    https://api.stlouisfed.org/fred/series/search?search_text=copyright&api_key=your_api_key
    ERROR: The directory (/opt/sas/viya/config/data/cas/default/public/fred) does not exist or cannot
    be accessed.
    ERROR: Libref FRED is not assigned.
    ERROR: Error in the LIBNAME statement.
    17 data mylib.UnemploymentClaims;
    18 set fred.UnemploymentClaims;
    ERROR: Libref FRED is not assigned.
    19 run;

    ERROR: Library MYLIB does not exist.
    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: DATA statement used (Total process time):
    real time 0.01 seconds
    cpu time 0.01 seconds

    20 proc print data=mylib.UnemploymentClaims;
    ERROR: Library MYLIB does not exist.
    21 run;

    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE PRINT used (Total process time):
    real time 0.01 seconds
    cpu time 0.01 seconds

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top