10-09-2016 01:01 AM
I am trying to import income statement info for the stock MNKD, here is the link:
I would like to download the income statement info, but when I try do get some elements, I inspect an element and get its id and then put this id in my code, but all I get is hundreds of empty rows.
Is there a way to get this kind of data?
10-09-2016 01:39 AM - edited 10-09-2016 01:47 AM
here is the code:
proc sql noprint ;
into :symbol separated by ' '
%let symbol= %scan(&all_data, &k);
%do %while("&symbol" NE "");
filename &symbol url " https://ca.finance.yahoo.com/q/is?s=&symbol&annual " debug;
data &symbol ;
infile &symbol dsd lrecl = 128 firstobs=2;
input yfnc_tabledata1 ;
format stock $5.;
stock = "&symbol";
%let k = %eval(&k + 1);
%let symbol = %scan(&all_data, &k);
yfnc_tabledata1 is the html id of the table which I am trying to import.
10-10-2016 04:45 AM
As with all posts like this, you are trying to run before you can walk. Remove all the macro stuff, get some Base SAS code working first - this is the programming language after all not macro. So lets look at the basic code:
filename temp url "https://ca.finance.yahoo.com/q/is?s=MNKD&annual" debug; data kknd; infile temp dsd lrecl=128 firstobs=2; input yfnc_tabledata1 ; format kknd $5.; stock = "kknd"; run;
So I am afraid to say, this whole process you have here is not going to work.
10-10-2016 11:15 AM
I prevously obtained the daily prices for the stock in a similar way and it actually worked!
1) Concerning the "&annual", in my code for stock prices I had even more &s:
filename &symbol url " http://ichart.finance.yahoo.com/table.csv?s=&symbol&d=11&e=2&f=2015&g=d&a=9&b=1&c=2015&ignore=.csv " debug;
2) Format stock $5. is actually a new column that I included that contians the stock's ticker like this when I append all the stocks data together I know which data belongs to which stock.
3) I had "input date adjclose", and like this got only the date and its adjusted close price, since date and adjclose are html elements.
Now I am tryig to get the entire table, but as I already mentioned I get empty rows...
10-10-2016 06:51 AM
You are connecting HTTPS . You can't get any result unless you configure something at SAS side. Check the documentation of proc http.
Alternative way is using CURL to get data and import it by SAS.
10-10-2016 11:41 AM
I actually already imported daily stock price and my code, similar to this one worked. The web page of the daily prices was also https, but in my code I used only http and it still worked.
It seems to me that what I am inputting is wrong, but I might be mistaken....
10-11-2016 07:21 AM
That is odd. When running the following code. I get Time Out ERROR. I can't get any data for it due to HTTPS.
filename temp url "https://ca.finance.yahoo.com/q/is?s=MNKD&annual" debug; data _null_; infile temp ; input ; put _infile_; run;
10-11-2016 05:03 PM - edited 10-11-2016 05:09 PM
I also ran your code and got an empty table. Looking at the log, it seems that it actually shows the html text. I can actually get the html with the following code:
length view $32767;
filename the_vid url "http://ca.finance.yahoo.com/q/is?s=MNKD&annual";
infile the_vid lrecl=32767;
view = _infile_;
The income statement info is actually present in the table "download", but its a mess to get it out...
That's why I thought if it were possible to get the income statement table in table form, just like it is possible to get the daily price in table form. But on the other hand, the daily price is actually a csv file, whereas the income statement it raw html.
10-11-2016 10:42 PM
Still got error, Maybe there is a problem at my side, I am in China.
34 data download;
35 length view $32767;
36 filename the_vid url
36 ! 'http://ca.finance.yahoo.com/q/is?s=MNKD&annual';
37 infile the_vid lrecl=32767;
39 view = _infile_;
ERROR: 10060 - WSAETIMEDOUT.
NOTE: The SAS System stopped processing this step because of
WARNING: The data set WORK.DOWNLOAD may be incomplete. When
this step was stopped there were 0 observations and 1
NOTE: DATA statement used (Total process time):
real time 21.02 seconds
cpu time 0.09 seconds
10-11-2016 11:55 PM
Tried it in both UE and 9.2 .
Here is some basic idea, you can start out with it.
filename the_vid url 'http://www.sas.com'; data download; infile the_vid recfm=n dsd dlm='<>'; input view : $200. @@; run;
10-12-2016 01:44 AM
I ran the code, it indeed did some cleaning to the html.
I was wandering if it is possible to download specific html elements and not the whole html of the page. In my case the class of the table that I try to download is yfnc_tabledata1, bu when I input it in the code I get a variable yfnc_tabledata1 but with empty rows.