The SASEQUAN Interface Engine

Getting Started: SASEQUAN Interface Engine

You can query the Quandl data set to retrieve the observations or data values for a list of economic time series by specifying the Quandl code of the data set. The Quandl code consists of a source code and a table code for the data set that contains the time series that you want to read into SAS. You must also specify your unique Quandl API key (authentication token for unlimited access). To obtain your own unique API key, visit the Quandl website at the following URL: http://www.quandl.com/users/sign_up .

The Quandl API key is a 20-character mixed-case alphanumeric string, such as "abCDefghiJKLMn123456," and is represented by ’XXXXXXXXXXXXXXXXXXXX’ in the APIKEY= option in the following example. In addition, the example URLs in this section and in the section Details: SASEQUAN Interface Engine use the same Quandl API key as the argument your_quan_apikey.

After you have your assigned Quandl API key and have agreed to the Quandl terms of use, but before you download any copyright-protected data series, be aware that you are solely responsible for obtaining copyright permissions for any copyright-protected time series that you download (other than for personal use).

Now that your are informed about the terms of use of the Quandl data, you can use your Quandl API key to access the Quandl data, as shown in the following example.

The statements that follow enable you to access the prices for oil from the National Stock Exchange of India’s time series data from September 1, 2013, to November 5, 2013, on a daily basis. The observations are sorted by the time ID variable DATE. The output is shown in Figure 43.1.

options validvarname=any;
title 'Retrieve Data for Oil India Limited Prices';
libname _all_ clear;

libname quan sasequan "%sysget(QUANDL)"
   OUTXML=oil
   XMLMAP="%sysget(QUANDL)oil.map"
   APIKEY='XXXXXXXXXXXXXXXXXXXX'
   IDLIST='NSE/OIL';

data oil_gsa;
   set quan.oil;
run;
proc contents data=oil_gsa; run;
proc print data=oil_gsa(obs=15); run;

Figure 43.1: Oil India Limited Prices: Oil_Gsa (OBS=15)

Retrieve Data for Oil India Limited Prices

Obs date Open High Low Last Close Total Trade Quantity Turnover (Lacs)
1 2009-09-30 1096.00 1156.70 1090.00 1135.00 1141.20 19748012 223877.07
2 2009-10-01 1102.00 1173.70 1102.00 1167.00 1166.35 3074254 35463.78
3 2009-10-05 1152.00 1165.90 1136.60 1143.00 1140.55 919832 10581.13
4 2009-10-06 1149.80 1157.20 1132.10 1143.30 1144.90 627957 7185.90
5 2009-10-07 1153.80 1160.70 1140.00 1141.45 1141.60 698216 8032.98
6 2009-10-08 1145.00 1179.80 1142.00 1178.10 1170.20 788173 9138.99
7 2009-10-09 1176.00 1210.00 1165.00 1183.00 1195.65 1047417 12449.44
8 2009-10-12 1184.00 1210.00 1176.00 1193.00 1195.70 464697 5551.35
9 2009-10-14 1198.00 1227.75 1185.00 1192.50 1190.45 581221 7015.84
10 2009-10-15 1198.00 1204.90 1180.05 1184.90 1184.55 301790 3593.52
11 2009-10-16 1188.65 1203.00 1182.00 1191.10 1191.00 313011 3735.12
12 2009-10-17 1240.00 1240.00 1180.00 1189.10 1189.80 35143 418.95
13 2009-10-20 1196.00 1203.50 1172.00 1174.00 1177.85 156941 1861.75
14 2009-10-21 1184.00 1194.00 1157.00 1166.00 1166.10 309098 3657.14
15 2009-10-22 1165.00 1184.40 1158.00 1168.00 1164.95 338413 3973.97



The XML data that the Quandl website returns are placed in a file that is named by the OUTXML= option—in this case, OIL1.xml. Note that the SASEQUAN engine appends a numeral to the XML filename, and the file extension (.xml) is excluded from the filename that appears in the OUTXML= option. This XML data file resides in the location that is given inside the string enclosed in double quotation marks in the SASEQUAN LIBNAME statement. So, in the preceding example, if the QUANDL environment variable is set to

   C:\quandata\

then the downloaded XML file is located at

   C:\quandata\OIL1.xml

An equivalent LIBNAME statement that does not use any environment variables could be as follows:

   libname quan sasequan "C:\quandata\"
      OUTXML=oil
      XMLMAP="C:\quandata\oil.map"
      APIKEY='XXXXXXXXXXXXXXXXXXXX'
      IDLIST='NSE/OIL';

You could also use either a SAS macro variable or a system environment variable to store the value of your Quandl API key so that the key does not appear explicitly in your SAS code. The XML map that is created is assigned the full pathname that the XMLMAP= option specifies. The SASEQUAN engine appends a numeral to the XML filename to indicate the position of the Quandl code in the IDLIST= option.

The IDLIST= option specifies the list of Quandl data sets (that contain time series) that you want to retrieve. This option accepts a string, enclosed in single quotation marks, that denotes a list of one or more Quandl data sets that you select (keep) in the resulting SAS data set. The result, OIL, is named in the DATA step and is shown in Figure 43.1. The preceding example uses only one Quandl code, which is in the first position of the IDLIST= option, so the numeral 1 is appended to the name of the XML file, resulting in OIL1.xml.

It is more efficient to use the DATA step to store your Quandl data in a SAS data set and then refer to the SAS data set directly in your PROC PRINT or PROC GPLOT statement. You can also refer to the SASEQUAN libref directly, as in the statement

   proc print data=quan.oil; run;

This statement uses the member name, OIL, in the PROC PRINT statement; this usage corresponds to specifying the OUTXML=OIL option. Although using this statement might seem easier, it is not as efficient, because every time you use the SASEQUAN libref, the Quandl interface engine reads the entire XML file into SAS again. So it is better to refer to the SAS data set repeatedly than to invoke the interface engine repeatedly. For another example that uses more SASEQUAN LIBNAME statement options, see the section Reading All Financial Ratios Data.