Tuesday, February 9, 2010

Checking for Issues in SAS

I've been working on a macro program to check the SAS log for specific "issue" keywords, including "error", "warning", "invalid", and "uninitialized". Typically these are associated with issues in the program. I'm considering adding the following statements as well:
  • "The query requires remerging summary statistics back with the original data"
  • "Numeric values have been converted to character values"
  • "Character values have been converted to numeric values"
The above statements may not always be associated with issues; however, there are better ways to write the program then to allow these statements to occur. For example, if the programmer wants to set a character variable to the text value of a numeric variable, it is better to use a put statement then to allow SAS to do it, as it may convert it incorrectly. Here's an example:

data _null_;
    today=today();
    call symput('today',today);
run;
%put NOTE: Today is &today;

The example sets today's date as a macro variable called today. However, the output is just a number. Depending on how the macro variable is used, this may be okay. Here's a better way to write it:

data _null_;
    today=today();
    call symput('today',compress(put(today,8.)));
run;
%put NOTE: The date value of today is &today;

Or, even simpler:

data _null_;
    today=today();
    call symputx('today',today);
run;
%put NOTE: The date value of today is &today;

Adding the "x" to the call symput statement will automatically set the numeric variable to character and remove spaces.

If the programmer actually intends to write out the date in a date format, then the following code will work. (Note that the date format can be whatever format desired. I like the YYMMDDN8 format since it sorts better.)

data _null_;
    today=today();
    call symput('today',put(today,yymmddn8.));
run;
%put NOTE: Today is &today;

The macro program I've written can identify these types of issues so they can be corrected. I've also recently discovered that other SAS users have created such log checking utilities, and they include more phrases that would indicate issues within various procedures that I do not use frequently. Once I have time to review these statements, I will include them in my program as well.

In addition to identifying these issues, I'm filtering out common issues that occur with the above keywords that are probably not associated with issues in the program. For example, a libname error from an autoexec program may not be an error for the program if it is not used. If it is used, there will be subsequent errors that would identify the issue.

This type of non-issue occurs at work frequently. We have a generic autoexec that runs when SAS is started, and it includes libnames that are located in directories I do not have the security rights to view. Therefore, every time I start SAS there are errors in the log. When I check the log for issues, I do not want these generic issues to appear.

How do you check for issues in a SAS program? Do you have a utility for doing so? What do you check for?

Saturday, January 30, 2010

Goals for 2010

At work, upper management set corporate and division goals, and asked everyone to submit personal goals that align with the corporate and division goals. Here are my official goals:
  • Complete all tasks as assigned for HEDIS 2011
  • Submit HEDIS 2010 measures to NCQA
  • Complete any post-HEDIS analyses
  • Complete an internal leadership course
  • Coordinate two projects to completion
In addition, I have these goals:
  • Complete another AHIP course
  • Complete another SAS course (advanced macros or programming 3)
  • Share SAS tools (e.g., macros, autoexecs) with other users
I would really like to increase the communication between SAS users at work, so we can share processes, tips and tricks, macros, and programming methodologies. In part, this would enhance my skills as a SAS programmer, and it would also help make our SAS programs more standardized, increasing consistency, efficiency, and competitive edge.

What goals do you have for 2010?

Wednesday, December 9, 2009

Snow Day

If you're living in Wisconsin, you know that today, December 9th, is a snow day. It has snowed over 14 inches in the past day, schools are canceled, and even business days have been canceled. My family stayed home today.

For a very short time, we went outside. My son, Luca has been quite entranced by the snow, staring out the window without any attention for anything else. When we went out, it was a bit difficult for him to move around with all of the winter cloths and all the snow. I thought it would be funny to stick him in the snow drift and take a picture. My wife, Kyra, said the tree near our home would be perfect for the scene:



Luca tried to crawl out of his snow trap... He ended up going face first into the snow right after this shot. We went inside right after that!



We were quite bored inside all morning, so after we came back inside, Kyra suggested that Luca and I play with some shaving cream. I guess he's done this at preschool before, and it sounded like a fun activity to keep him occupied. I spread shaving cream on the dining room table and he went to town. I thought it was quite amusing, so I spread some shaving cream in his hair. When I did that he smeared it all over his face...



We hope the snow will clear up soon, so we can get back to work and our normal lives! Stay safe everyone!

Wednesday, September 16, 2009

Colors in the SAS Log

Today I was writing a SAS program, and I wanted a statement I was writing to the log to appear in a different color, so the user could find the information easily by scanning the log. My supervisor wrote a macro program that output a note at the end that appeared red in the log. So I looked up the program to see how he did it.

To my surprise, the macro program uses a simple %put statement with the word ERROR at the beginning, followed immediately by a dash (-). The dash removes the word "ERROR" from the log, replacing it with 5 spaces. This is apparently a default function in SAS. He also added a %str statement inside the word ERROR to break it up, so users do not see the word "ERROR" when the program is included in another program and the user searches the log for errors. Here is the code:

%put ER%str(ROR-) Here is text in red!;

This technique can also be used for the keywords WARNING and NOTE:

%put WA%str(RNING-) Here is text in green!;

%put NO%str(TE-) Here is text in blue!;

Note that the placement of %str() is arbitrary. It could just as well be "%str(W)ARNING-". Keep in mind that the end result is also indented the length of the key word, with blue being the shortest and green being the longest indent. Furthermore, there isn't much point in removing the word "NOTE" since it is generally not associated with error messages.

In the end, only four colors can be used in the log: the default black, red, green, and blue. Blue is the easiest to use, since the key word NOTE does not need to be removed. Having red and green also available, though, is definitely better than nothing!

Tuesday, July 28, 2009

IBM Buys SPSS & SPSS vs SAS

Announced earlier today, IBM is to buy SPSS, the statistical and predictive modeling software and competitor with SAS. (More news articles.)

I used SPSS at my last job, and I liked it quite a bit. There were certain tasks that were much easier using the windowing interface, and SAS's code-only method just doesn't quite match that. For example, transposing a dataset in SAS is not very intuitive. In SPSS, however, the wizard explains which variables to choose for identification of variables, constants, and variables to transpose.

Then on the other hand, SAS is quite powerful and is capable of a lot more than SPSS. Perhaps SPSS's code module can be used in a similar way, but when I used it, it was rather annoying. If you need to use a dataset, it required it to be open. In SAS, you don't ever have to open a dataset, unless you need to figure out what the variables are like. Then again, you can just look at the column information in the context menu. SAS flows from one dataset to another, and there's no need for the dataset to pop-up when using it.

SPSS was much better at handling variables (columns). Variables could be easily changed from one type to another, and "labels" for particular variables could be applied. For example, 1 = Low, 2 = Medium, and 3 = High. This can be accomplished in SAS with formats, but it's not quite the same, as it requires the user to apply the format. SPSS was also quite useful for turning a variable into a category or a variable with ranges; for example, converting salaries into salary ranges. A window wizard helped with that too.

At any rate, it will be interesting to see what happens in this market now that IBM is going to own SPSS. I always thought SPSS and SAS joined together would be a really great product, and perhaps IBM will bring to SPSS more SAS-like capabilities. Who knows?

More comparisons of SPSS and SAS: