Tag: coding

SAS Stored Process: Ignore the Log at Your Own Peril

I love our readers – especially when they have a great idea they want to share. Quentin McMullen, who has been programming in SAS for 15 years, primarily in clinical trials and public health…

[Read the full article at the Http://www.bi-notes….

Quick HTML Guide for SAS Programmers

The SAS BI web clients each have their own link (or URL).  When working across many customer sites or even just using my own demo sites –  there can be a lot of links to track (BI Dashboard, Portal, WRS, etc). Certainly I can add bookmarks to my browser –  but when moving to different systems I found it’s easier to just have a little .HTML file that I can edit as needed. Set Your BI Toolset Quick Ref Bookmark If you are not sure what I’m trying to describe –  the following page shows an example. It’s really just a simple web page that has the links to the SAS BI Web Clients listed.  In this example –  the customer had two different servers –   Development and Production. Using this quick reference, I can edit the HTML file to match the system I’m using, open the page in the browser, click on the link and it starts the client I want. To make this web page easier to access – I set it as a default so it appears when I start Internet Explorer.  You can set your default home page in the Tools > Internet Options window.  [Other browsers have […]

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 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: […]

Web Report Studio: Adding Drill-Down Filter Based on a Date

When I was creating the Summary and Detailed reports for the SAS Global Forum paper, I was demonstrating how to link from the weekly chart to the detailed report about the week.  On my first try with my Week Filter based on the date value – it just would not work.  Eeek!  To fix the problem I made a new data item that was a character value.  This posts talks about my strategy.  [You can read our paper “Get Your Fast Pass to Building Business Intelligence with SAS and Google Analytics”.  The presentation goes into more detail, but here’s some past articles about Google Analytics. ] What Should Happen When you click on the bar that represents the week – you actually drill-down to the Weekly Detailed report. You cannot use a date value as this filter – you must use a character based filter for this prompt.  If you need help setting up the filter or creating the link – just refer to the  ”Get Your Fast Pass to Building Business Intelligence with SAS and Google Analytics” paper. Creating the Proper Filter in the Information Map First you need to create a data item based on the date variable.  I used a CASE statement to test if the week was […]

SAS Stored Processes: 3 Tips to Improve Your Prompts

SAS stored processes are similar to SAS programs in that they use the same programming language.  Many of my SAS programs I created early on were only used by me, so I could live with  a little uncertainty and it was easy enough to check the logs for any issues.  If anything went wrong then I knew what I had to change. Stored processes required a whole new level of thinking – my first few stored processes back in the SAS 9.1.3 days were – well they left a lot to be desired.  When I would roll out a new stored process I would often get a call from a user who had done something crazy and the stored process wouldn’t work.  For instance, why would anyone put a state name in a customer name field to see if it would return all the customers from that state?  Only one thing could happen – no report!   Here’s some usability tricks that I have learned with my SAS Stored Processes to make them more robust and harder to break.  Really the out-of-the box prompts provide a lot of functionality that really helps. That’s right – let’s build a better mousetrap! Tip #1: […]

SAS Coding: 3 Data Set Tricks in PROC SQL

Maybe you are like me and your SAS programs frequently bounce from PROC SQL to data steps depending on the task at hand. Some things you cannot do in PROC SQL as easily as the data step and vice versa.  Here’s 3 data set tricks that I have successfully used with PROC SQL.  These are some time savers that you can use in your work.  However, if you know some others add them in the Comments section – I double-dare you.   Trick #1: Drop and Keep Options You can use the DROP and KEEP options on the FROM or CREATE statements. This is handy when you want to exclude or include a list of variables.  Consider this example where I saved myself some typing because I know the only variable I don’t want is country. Otherwise I would have had to type out all of the other variables just to exclude a single one. proc sql; create table Newtable  as    select * from sashelp.prdsal2(drop=country);quit;  Trick #2: Limit the Observations OBS allows you to control the number of observations input to the procedure.  I would use this if I had a particularly large data table and I just needed to test […]

Using SAS to Automatically Forecast

In honor of Easter, here’s a rare egg for the BI Notes blog – information about SAS statistical products! Today guest blogger Phil Low offers some insight about some of the other SAS procedures, particularly those used for the forecasting. Would You Manually Forecast 60,000 Data Items? Ever wake up to find you have to produce forecasts for 60,000 different items? As a data analyst for a medical supply distributor, I have. Manual forecasting under these conditions is neither feasible nor profitable. Enter the FORECAST and ESM procedures. These two procedures combined can produce more than 10 different forecast models to choose from, and can easily be compared against each other with goodness of fit stats. The FORECAST procedure was written in the 1980s and is a simple auto regression with or without trend. Stepwise selection is used to determine which autoregressive lags make it into the final model. Because it is so old, some the more advanced features are better represented by ESM or AUTOREG. The ESM procedure is a moving average model. What’s great about ESM is its ability to throw deterministic trend and seasonality into the mix. You can customize just about every aspect of the model […]

SAS Enterprise Guide: Check the Log Macro

I created a LogCheck macro [code provided] to review the log during a batch process. The SAS log files can be rather large and it is so much easier if you can just extract the issues in an easy to understand format. This macro reads in each line of the log file and keeps the ones with Error, Warning, Note, or specific text you want to trap.  Then it sends a colorful email to report what issues (if any) were found. You can download the code and two sample programs to review or change for your situation.  Let me know what you think in the Comments section.  How can the code be improved?  Any ideas you have?   Using the LogCheck Macro Add the LogCheck macro to your batch job to report issues through email about the job.  When the job has no errors, you will receive an email similar to the following.  The subject line indicates no found issues – thus you have some assurance the job was successful. When the job has errors – the macros sends an email similar to the following.  Notice the subject line contains the number of Errors, Warnings, and Notes present in the […]