/* A list of sample links from the SAS Dummy blog */ /* YTD 2012 blog topics as of July */ data links; infile datalines dsd; length url $ 255; input url; datalines; http://blogs.sas.com/content/sasdummy/2012/01/03/pitfalls-of-the-lag-function/ http://blogs.sas.com/content/sasdummy/2012/01/11/uncovering-the-hidden-parts-of-the-sas-log/ http://blogs.sas.com/content/sasdummy/2012/01/18/sasondemand-forpros/ http://blogs.sas.com/content/sasdummy/2012/01/19/sas-is-no-3/ http://blogs.sas.com/content/sasdummy/2012/01/25/export-to-excel-got-easier/ http://blogs.sas.com/content/sasdummy/2012/01/27/achieving-mediocrity/ http://blogs.sas.com/content/sasdummy/2012/02/02/profiles-via-eg-automation/ http://blogs.sas.com/content/sasdummy/2012/02/11/export-excel-methods/ http://blogs.sas.com/content/sasdummy/2012/02/22/about-sas-report-format/ http://blogs.sas.com/content/sasdummy/2012/03/01/precision-in-sas-numbers/ http://blogs.sas.com/content/sasdummy/2012/03/06/be-a-code-poet-laureate/ http://blogs.sas.com/content/sasdummy/2012/03/07/sasgf2012-closing-sessio/ http://blogs.sas.com/content/sasdummy/2012/03/12/making-up-for-lost-time-utc-dst/ http://blogs.sas.com/content/sasdummy/2012/03/15/how-many-obs-sysnobs/ http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/ http://blogs.sas.com/content/sasdummy/2012/03/23/improving-on-a-sas-programming-pattern/ http://blogs.sas.com/content/sasdummy/2012/04/01/new-certification-program-sas-versions-professional/ http://blogs.sas.com/content/sasdummy/2012/04/03/64-bit-versus-32-bit-apps/ http://blogs.sas.com/content/sasdummy/2012/04/11/the-heme-finder-where-ill-be-during-sas-global-forum/ http://blogs.sas.com/content/sasdummy/2012/04/12/build-your-own-sas-data-set-viewer-using-powershell/ http://blogs.sas.com/content/sasdummy/2012/04/17/doing-more-with-sas-enterprise-guide-automation/ http://blogs.sas.com/content/sasdummy/2012/04/18/sas-tech-talks/ http://blogs.sas.com/content/sasdummy/2012/04/19/myths-about-64-bit-computing-on-windows/ http://blogs.sas.com/content/sasdummy/2012/04/29/the-makeup-of-sas-global-forum/ http://blogs.sas.com/content/sasdummy/2012/05/01/64-bit-gotchas/ http://blogs.sas.com/content/sasdummy/2012/05/09/powershell-read-sas-data-files/ http://blogs.sas.com/content/sasdummy/2012/05/15/how-long-will-eg-process-run/ http://blogs.sas.com/content/sasdummy/2012/05/18/using-proc-sql-to-get-the-schema-of-a-mysql-database/ http://blogs.sas.com/content/sasdummy/2012/05/22/windows-reg-query-from-sas/ http://blogs.sas.com/content/sasdummy/2012/05/23/sas-on-a-video-game-system/ http://blogs.sas.com/content/sasdummy/2012/06/04/top-gear-for-sas-professionals-knowledge/ http://blogs.sas.com/content/sasdummy/2012/06/07/egp-search-tool/ http://blogs.sas.com/content/sasdummy/2012/06/12/high-performance-analytics-it-may-be-a-show-is-no-act/ http://blogs.sas.com/content/sasdummy/2012/06/14/read-a-microsoft-date-time-value-into-a-sas-date-time-value/ run; /* Get count of URLs in source data */ /* Here it assumes WORK.LINKS */ /* and the page link to check is in the URL column */ proc sql noprint; select count(URL) into :urlCount from WORK.LINKS; quit; /* trim this for later use in constructing data set names*/ %let urlCount = %trim(&urlCount); %macro gatherSocialStats; /* This loop reads each URL link from the data set */ /* one at a time, and then uses FILENAME URL */ /* to invoke the Twitter and Facebook APIs for */ /* Tweet counts and Share counts */ %do i = 1 %to &urlCount; /* read the next URL */ proc sql noprint; select trim(url) into :url from work.links(firstobs=&i obs=&i); quit; %put Checking %str(&url.); /* format of the Twitter API call */ filename twurl url "http://urls.api.twitter.com/1/urls/count.json?url=&url." /* supply PROXY= option if behind a corporate firewall/gateway */ ; /* format of the Facebook API call */ filename fburl url "http://graph.facebook.com/?ids=&url." /* supply PROXY= option if behind a corporate firewall/gateway */ ; data twresult&i; /* Running in EG? SYSECHO helps convey progress in status bar */ SYSECHO "Checking Tweet URL &i. of &urlCount."; length line $ 500 url $ 500; infile twurl; url = "&url."; input line; run; data fbresult&i; /* Running in EG? SYSECHO helps convey progress in status bar */ SYSECHO "Checking FB URL &i. of &urlCount."; length line $ 500 url $ 500; infile fburl; input line; url = "&url."; run; /* Free up the filerefs */ filename twurl clear; filename fburl clear; %end; /* concatenate all Twitter counts */ data twresults; set twresult1-twresult&urlCount.; run; /* concatenate all Facebook share counts */ data fbresults; set fbresult1-fbresult&urlCount.; run; /* clean up all of the tiny data sets */ proc datasets lib=work nolist; delete twresult1-twresult&urlCount.; delete fbresult1-fbresult&urlCount.; quit; %mend; %gatherSocialStats; /* Post processing to PARSE the results, which */ /* are in JSON format */ /* Example result: { "http://blogs.sas.com/content/sasdummy/2012/01/25/export-to-excel-got-easier/": { "id": "http://blogs.sas.com/content/sasdummy/2012/01/25/export-to-excel-got-easier/", "shares": 3 } } */ data work.fbcounts (keep=fbshares url); set fbresults; length fbshares 8; if _n_ = 1 then do; retain fb_regex; /* looking for "shares": */ fb_regex = prxparse("/\""shares\""\:([0-9]*)/"); end; position = prxmatch(fb_regex,line); if (position ^= 0) then do; call prxposn(fb_regex, 1, start, length); fbshares = substr(line,start,length); end; run; /* Post processing to PARSE the results, which */ /* are in JSON format */ /* Example result: {"count":8,"url":"http:\/\/blogs.sas.com\/content\/sasdummy\/2012\/01\/27\/achieving-mediocrity\/"} */ data work.twcounts (keep=tweets url); set twresults; length tweets 8; if _n_ = 1 then do; retain tw_regex; /* looking for "count": */ tw_regex = prxparse("/\""count\""\:([0-9]*)/"); end; position = prxmatch(tw_regex,line); if (position ^= 0) then do; call prxposn(tw_regex, 1, start, length); tweets = substr(line,start,length); end; run; /* Join it all together with the URL, tweet counts, */ /* and share counts */ proc sql; create table work.socialcounts as select t1.url, ifn(t2.fbshares eq .,0,t2.fbshares) as fbshares, t3.tweets, /* date-stamp the value for use in history/comparisons */ today() as as_of_date format=date9. from work.links t1 left join work.fbcounts t2 on (t1.url = t2.url) left join work.twcounts t3 on (t1.url = t3.url) ; quit;