SAS Enterprise Guide: Writing Code to Capture New Twitter Followers

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.

While at the SAS Global Forum, someone said to me – “You cannot write code in SAS Enterprise Guide.”  It was a little shocking to me that the person thought SAS Enterprise Guide was all wizards, flow diagrams, and magic. After talking to a few other folks I have found that it is a common myth.  

News Flash!  You can just code in SAS Enterprise Guide!  Today I’ll show you how I pull data from Outlook into SAS Enterprise Guide to create a tweet.  And I’m just going to code.

Mythbuster! You can Code in SAS Enterprise Guide

If you tweet a lot then you might be familiar with the #FF hashtag. It means people the Tweet-er suggests that you follow. Lately I have been getting more Twitter followers and some I think are really worth checking out.  However, trying to cut and paste all the names into a tweet is a buzz kill.   Here’s how I automated my process with SAS Enterprise Guide.  By the way – if you think I could add some efficiency to my code – speak up in the comments (with examples please!) 

Step 1: Setup a MS Outlook Rule

Here’s the initial process:

  1. In MS Outlook, I created a New Followers folder.  Then I setup a rule so all the emails that had “now following you on Twitter” as the subject would automatically go to this folder.  
  2. Each Friday morning I cut-and-paste the email list into SAS Enterprise Guide.  
    Hint: To create a new program in SAS Enterprise Guide, select File > New > Program.  
  3. In SAS Enterprise Guide, just write your code!  
    In the example, I use a DATALINES statement to read the email titles.   This code extracts the Twitter_ID using the SCAN function.  I also capture how long the Twitter ID is and add 1 for the white space behind it.  (We’ll talk about this more in the next section.)
  4. Select Run (or F8) and my new dataset ReadOutlookData is created.  Everything is organized into tabs.  So just click the Output Data (2) to see the new data or the Log tab to check what happened.  Click Program to return to your code.

  

get friday follwers step11 1024x550 SAS Enterprise Guide: Writing Code to Capture New Twitter Followers

Step 2: Get the Twitter IDs

Tweets should not exceed 160 characters – some weeks I have a lot of new followers so the tweet can become larger than 160 characters. In this code, I use a counter to test if the count is 0 and start a new tweet with the hashtag.  Then I append the remaining Twitter IDs to the tweet.  Once the string exceeds 140 characters, I output it.  Sometimes I like to add other hashtags, such as #SASusers,  #blogger, or #DataGuru so I want plenty of room.  I look at all the followers and determine who seems like they have good stuff or maybe fit a certain category.

The program then loops through the code to create as many tweets as needed.  By the way – maybe there is a better way to write this code.  Since the dataset rarely exceeds 25 rows I was not worried about being efficient.  

get friday follwers step2 SAS Enterprise Guide: Writing Code to Capture New Twitter Followers

Step 3: Schedule the Tweet

Last step is to output as plain text so it’s easy to cut and paste to Hootsuite. Since I get up with the chickens, I like to schedule my #FF for later in the day so more people see the tweet.  

get friday follwers step3 1024x434 SAS Enterprise Guide: Writing Code to Capture New Twitter Followers

Proven to be True

It’s true – you can just code in SAS Enterprise Guide. By the way, SAS provides a free tutorial for SAS Enterprise Guide to help you learn about its features and uses.  Any comments on this method?  

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.