BI Tools

Tips and tricks for building information maps, OLAP cubes, reports, and dashboards

BI Admin

Learn your way around a SAS BI installation.

Visual Analytics

Learn your way around the SAS Visual Analytics tool

Coding & Data

Extract, transform, and load your data into the SAS BI toolset

Stored Processes

Create and design stored processes like a rock star

Home » Coding & Data

SAS Enterprise Guide: Writing Code to Capture New Twitter Followers

Submitted by on 2012-06-20 – 6:39 AM 6 Comments

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 got 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.


SAS Enterprise Guide Used to Code STep 1

Step 2: Get the Twitter IDs

Tweets should not exceed 140 characters – some weeks I have a lot of new followers so the tweet can become larger than 140 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 130 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.  

SAS Enterprise Guide Used to Code STep 2

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.  

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?  

Never miss a BI Notes post!

Click here for free subscription. Once you subscribe you'll be asked to confirm your subscription through your email account. You email address is kept private and you can unsubscribe anytime.
The following two tabs change content below.

Tricia Aanderud

Director of Data Visualization at Zencos Consulting
Tricia Aanderud is a SAS Business Intelligence and Visual Analytics consultant based in Raleigh, NC who works for Zencos Consulting. She has written several books about SAS, presented papers at many SAS conferences, and has been using SAS since 2001. Contact her for assistance with your next project.
Spread the love

Tags: , ,


  • Here’s where you find the free tutorial from SAS:

    If you open SAS Enterprise Guide then go to Help > Getting Started Tutorial it will take you to the training for your version. Here’s the Getting Started for Version 5.1. . However it appears general enough that you could learn how to use the basics in the tool.

  • Paul says:

    There is a link to “a free tutorial for SAS Enterprise Guide”, but it links back to this page! What is the correct link for this tutorial?

  • Great idea. I’ll modify my code.

    Let me know if you have any other ideas!

  • Zach says:

    Interesting use of SAS coding! One small addition… within the CNT = 0 do statement, the CNT variable should be calculated CNT = ID_Length + 8 to account for “Thx! #FF”. Otherwise, it could be common for your tweet to exceed 140 characters, even with the 130-character restriction you’ve written in.

    Also, it would be easy for you to exceed 140 characters, given that handles often exceed 10 characters. A more precise method would be to change the else line to “else if CNT + ID_Length lt 140 then do;” and add “else do; output; cnt = 0; end;” before the last line of code.

  • One eagle-eye reader reminded me that tweets can only be 140 characters – so I updated the text but did not update the code! Thanks!

  • Divyesh Dave says:

    For my current assignment, I program in Base SAS using SAS Enterprise Guide by going through the “File-New-Program” options. Base SAS is used so extensively that I don’t even use EG’s wizards such as “Query Builder”.