By · July 30, 2022 · 0 Comment
While exploring about Proc HTTP procedure in SAS, I wondered if it is possible to get list of all stock ticker in NASDAQ along with its basic information, which can be used for screening of stocks based on various parameter.
My quest leads me to NASDAQ api which gives stock screener based on exchange filter.
https://api.nasdaq.com/api/screener/stocks?exchange=nasdaq&download=true
Using Proc HTTP, I was able to get this data in form of JSON files and later converted to SAS Tables for further analysis.
filename nasdaq "C:\Project\stock\volume_res\data\nasdaq_list.json"; proc http url='https://api.nasdaq.com/api/screener/stocks?exchange=nasdaq&download=true' out=nasdaq; run; libname nasdaq json "C:\Project\stock\volume_res\data\nasdaq_list.json";
SAS Libname with json engine will enable us to view List of stocks listed in NASDAQ with basic details like SYMBOL, NAME, LASTSALE, VOLUME, MARKETCAP etc.
We can use this information for screening of stocks that fits our analysis criteria. For example, I want list of all NASDAQ stocks having market cap above 2 billion, having head office in USA.
We can also download list of all NYSE listed ticker using below URL
https://api.nasdaq.com/api/screener/stocks?exchange=nyse&download=true
Based on above list from both NASDAQ and NYSE, we can append both tables and filter based on our screening criteria.
/**************************************************************/ /*Part 1: Finding the list of stock from nasdaq */ /* and nyse having market cap above 1 Billion */ /************************************************************/ libname volume "C:\Project\stock\volume_res\data\daily"; filename nasdaq "C:\Project\stock\volume_res\data\nasdaq_list.json"; proc http url='https://api.nasdaq.com/api/screener/stocks?exchange=nasdaq&download=true' out=nasdaq; run; filename nyse "C:\Project\stock\volume_res\data\nyse_list.json"; proc http url='https://api.nasdaq.com/api/screener/stocks?exchange=nyse&download=true' out=nyse; run; libname nasdaq json "C:\Project\stock\volume_res\data\nasdaq_list.json"; libname nyse json "C:\Project\stock\volume_res\data\nyse_list.json"; Data list; length symbol $10.; set nyse.data_rows (keep=symbol marketcap volume) nasdaq.data_rows (keep=symbol marketcap volume); run; /*General data cleaning for Tickers not supported by*/ /*Trading platform*/ data list_1; set list; marketcap= marketcap/1000000; if symbol = compress(symbol,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",'k') and length(symbol) <= 4 and marketcap ne . and (marketcap)>=1000; date =datetime(); format date datetime20.; run;
In next post, I will try fetch historical stock data from web ..
–Pallav Lodhia