Using SAS to count the number of LinkedIn "shares" for your article


Last year I shared this popular tip for counting how many times a web link has been shared on Twitter or Facebook. I use this technique daily to report on the social media "popularity" of our blog articles at SAS.

I wanted to add LinkedIn into the mix. Like Twitter and Facebook, LinkedIn also has a REST-based API that can be used within a SAS program. For example, if I want to know how many times my recent post "It's raining analytics" has been shared on LinkedIn, I can use PROC HTTP to hit this URL:

Update 15Dec2014: LinkedIn recently changed their API endpoint to support a higher level of encryption, and as a result the programmatic use of the API requires the HTTPS protocol instead of HTTP. If you receive an error such as: "ERROR: SSL Error: Missing CA trust list", try using HTTPS in your API call.

Here is the JSON-formatted response (as of today):

IN.Tags.Share.handleCount ( { "count":89, "fCnt":"89", "fCntPlusOne":"90", "url":"http:\/\/\/content\/sasdummy\/2013\/01\/15\/its-raining-analytics\/" } );

Wow! That blog post has done pretty well on LinkedIn (with "count"=89) - it's my most-shared post this year.

Here's a SAS program that checks the LinkedIn shares for me:

%let url=;

/* temp holding area for LinkedIn response */
filename li temp;

/* call the LinkedIn API */
proc http
  /* proxyhost= if behind corp firewall */

/* use RegEx to gather the "count":n  value */
data liresult (keep=url lishares);
  length line $ 1000 lishares 8;
  length url $ 300;
  url = "&url.";
  infile li;
  input line;

  if _n_ = 1 then
      retain li_regex;
      li_regex = prxparse("/\""count\""\:([0-9]*)/");

  position = prxmatch(li_regex,line);

  if (position ^= 0) then
      call prxposn(li_regex, 1, start, length);
      lishares = substr(line,start,length);

/* clear our temp response file */
filename li clear;


That's a lot of code to retrieve the answer for just one link. Thanks to the power of the SAS macro language, I can scale this to retrieve the values for an entire collection of links. With those results in hand, I can run other stats:

Of my 63 posts in the past 12 months, my links have been shared to LinkedIn an average of 4.58 times, with a total of 289 shares overall.

I'm not so naive that I consider these to be impressive numbers, but I've only just begun the habit of sharing my posts on LinkedIn. With this process as part of my daily blog reporting, I can now measure how my "LinkedIn engagement" improves as I share more content. Collect data, count, measure, report -- that's what it's all about, right?

Note: Many web articles, such as blog posts, can have multiple URLs. For example, the WordPress platform offers "short-link" GUID URLs as well as the longer, more descriptive URLs. While all of these different URLs might lead to the same page, LinkedIn counts only the URL you share. So if you are in the habit of publicizing different URLs for convenience or other tracking purposes, you might need to check each permutation of a page URL with this program to get the complete "LinkedIn shares" picture.

Reference example

Complete macro version of my LinkedIn shares program (


About Author

Chris Hemedinger

Director, SAS User Engagement

+Chris Hemedinger is the Director of SAS User Engagement, which includes our SAS Communities and SAS User Groups. Since 1993, Chris has worked for SAS as an author, a software developer, an R&D manager and a consultant. Inexplicably, Chris is still coasting on the limited fame he earned as an author of SAS For Dummies


  1. Hi Chris,

    When i am using the PROC HTTP step i get an error.Looks like i may need a PROXY HOST= option : How do i find out the PROXY HOST?

    Here is the log i see:

    21 %let url=;
    23 /* temp holding area for LinkedIn response */
    24 filename li temp;
    26 /* call the LinkedIn API */
    27 proc http
    28 url=""
    29 method='GET'
    30 /* proxyhost= if behind corp firewall */
    31 out=li;
    32 run;

    NOTE: PROCEDURE HTTP used (Total process time):
    real time 0.01 seconds
    cpu time 0.00 seconds

    NOTE: The SAS System stopped processing this step because of errors.

    • Chris Hemedinger
      Chris Hemedinger on


      If you're behind corporate firewall, your IT group might have to tell you the PROXYHOST url. It's also configured in your Internet Options (used by the browsers such as IE or Chrome), but the settings might be indirect (set to "auto detect").

      You can try to add the VERBOSE option to PROC HTTP for more info:

      proc http 
        method='GET' VERBOSE
        /* proxyhost= if behind corp firewall */

      • Thanks Chris , I will contact my IT group. One final question.My SAS code runs on a Unix Server and i submit the code via SAS EG Windows Client.Does this matter at all with respect to knowing the correct PROXY HOST url?

        • Chris Hemedinger
          Chris Hemedinger on

          Yes, it can make a difference. That is, the fact that you're running on UNIX means that SAS can't "autodetect" the proxy from your Windows settings, so that's why you need to specify the proxy host. If it's on a non-standard port you might also need to specify the PROXY port and maybe even credentials. See all of the options here.

  2. Chris,
    Thanks for all the great examples!
    Can you help me understand what the "in" option does? There are several explanations of "out" (like this post), but "in" seems to not be used much.

    My situation is that I need to export a SAS dataset to a cvs file that will be sent in an HTTPS POST call to a REST API (specifically, for Can the "in" option do this? If not, can it be done in SAS 9.4 somehow (proc groovy? or some other method)?

    Otherwise, I'll have to produce the CSV and then manually upload it - but it would be nice to automate it.


    • Chris Hemedinger
      Chris Hemedinger on

      You're correct -- not too many examples with METHOD="POST" and use of the IN= reference to drive it.

      It looks like (from the API doc) that you can POST the data if you want. In that case, perhaps you can use SAS to create the CSV file, reference it with a fileref, supply that as the IN= argument, and use METHOD="POST". This will require experimenting on your part, obviously. But if you figure it out, "post" back here!

  3. Reggie Jones on


    I am trying to post information from a data set in sas to a web endpoint. I am new to this and need some assistance. For example, let's say I have a basic data step like below and I want to write a stored process in order to post this data to the endpoint below. Please show me the basic steps on how to do this.

    data a;
    set b;




  4. Pingback: Using SAS DS2 to parse JSON - The SAS Dummy

  5. Hi Chris,

    Great article.

    Is the way to count how many connection I have in a day ?

    Please advise thanks

    • Chris Hemedinger
      Chris Hemedinger on

      The only way that I know of to get to this is to capture the number of shares each day, then track the trend with your historical data.

  6. Pingback: Counting how many times a web link has been shared on Twitter or Facebook - The SAS Dummy

Back to Top