SAS Enterprise Guide: Writing Code to Capture New Twitter Followers
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:
- 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.
- 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.
- 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.)
- 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.
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.
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.
Latest posts by Tricia Aanderud (see all)
- Use Network Analysis to Understand Your Customers with SAS Visual Analytics 8.2 - 2018-01-21
- My 7 Favorite Features in SAS Visual Analytics 8.2 on Viya - 2018-01-14
- Creating a Web Analytics Report in SAS Visual Analytics 8.1 - 2017-06-19
- Designing Dashboards: Sending Your Style Vibe - 2017-01-21
- SAS Visual Analytics: Design Versus Reality - 2016-10-05