Susan Slaughter

Archive for June, 2010|Monthly archive page

Computing Ages in SAS: New Function Needed

In Everything, Little SAS Book Series, SAS, SAS Papers on June 29, 2010 at 12:44 pm

The following excerpt is from an e-mail message I sent to suggest@sas.com.  I know other people have suggested that we need a function designed specifically for computing ages, and I wanted to add my voice to that chorus.

“I would like to make a suggestion for Base SAS.  SAS needs a function that is designed specifically for the purpose of computing ages.

Looking back, I can’t believe that I didn’t suggest this 25 years ago, but at that time the people I worked with were satisfied to compute ages by dividing by 365.25. It was approximate, but we knew it was approximate so that was ok. The problem with computing ages using YRDIF or INTCK is that they appear to be more precise and accurate than they actually are—and that’s risky.

Computing ages is exactly the kind of thing that should be in The Little SAS Book, but the recommended method for computing ages using INTCK is just too complicated for this book.

In addition, the fact that INTCK counts the number of months and divides by 12 to compute ages in years is a little funky, in my opinion. Some people do want to compute decimal ages, and it might not be obvious to them that they can’t just remove the INT function to get decimal ages from INTCK. And why should you have to use more than one function to do something as ordinary as computing ages anyway?

And then there is the whole issue of negative time ranges. I don’t know if computing negative time ranges is a valid idea or not, but I do know that INTCK and YRDIF will let you do it—and the results are not consistent with each other. If you can compute negative ages, then they should be valid and consistent.

So here is my suggestion for an AGE function. It’s syntax would be

AGE(start-date, end-date, units, decimal-places)

where

Start-date would be a SAS date value for the beginning of the time period.

End-date would be a SAS date value for the end of the time period. If end-date is before start-date, then a missing value would be returned. (So no negative ages would be computed.) The keyword TODAY could be substituted for the end-date to compute current age. TODAY would be the default which would be used if no end-date is specified.

Units could have the value of YEARS or MONTHS to compute age in either years or months. YEARS would be the default.

Decimal-places would be a number indicating the number of decimal places. A value of 0 would produce integer values of age. 1 would produce ages with one decimal place, 2 would produce two decimal places, and so on. The default would be integer values.

If someone wanted to compute current ages in integer years, their statement would be something like this

CurrentAge = AGE(BirthDate);

Computing ages should be that simple—with no nested functions, and no IF-THEN/ELSEs required. If you write a function like this, then we would be happy to add it to The Little SAS Book.”

When I sent the above message to suggest@sas.com, the good folks at SAS Technical Support responded to let me know that they had received my message and that they were aware of my suggestion.  They did not say whether such a function is currently being developed, or whether they have any plans to develop such a function in the future.  If you need to compute ages in SAS, then you might want to share with SAS Technical Support your own ideas for the perfect function for computing ages.

Update:

Since I originally wrote this blog post, a new option has been added for the YRDIF function.  The AGE option fails to satisfy most of my suggestions listed here.  However, it does compute accurate ages and that is a huge improvement!  I am now happy to recommend this method for computing current age in integer years:

CurrentAge = INT( YRDIF(BirthDate, TODAY(), ‘AGE’));

YRDIF and Me: A Tale of Woe

In Everything, Little SAS Book Series, SAS, SAS Papers on June 29, 2010 at 12:37 pm

Update:

Since I originally wrote this blog post, a new option has been added for the YRDIF function.  The AGE option is not the easy-to-use option that I dreamed of.  However, it does compute accurate ages and that is a huge improvement!  I am now happy to recommend this method for computing current age in integer years:

CurrentAge = INT( YRDIF(BirthDate, TODAY(), ‘AGE’));

The original blog post:

In all the long history of The Little SAS Book: A Primer (four editions, five if you count the Revised Second Edition) we have removed only three topics from the book.   We dropped PROC COPY and PROC PLOT (that’s PLOT, not GPLOT or SGPLOT) because they had become largely obsolete.  Now we have removed the YRDIF function, but this situation is different. For the first time ever, we have removed a topic because it doesn’t work.

The YRDIF function has been removed from The Little SAS Book: A Primer, Fourth Edition, starting with the third printing, because it does not compute accurate ages. (YRDIF never appeared in earlier editions.)  In defense of YRDIF I have to point out that it does work the way it was designed to work; but YRDIF, it turns out, was never designed to compute ages.  Specifically, ages computed using the YRDIF function may be incorrect if the starting or ending date falls in a leap year, and the ending date is the person’s birthday. Of course, this situation doesn’t happen all that oftenbut it does happen. So, if you need really accurate ages, then you can’t use YRDIF.

We considered substituting some other method for computing ages (such as INTCK), but it turns out that not only are those methods too complicated to squeeze into the tiny space we had, they also come with their own limitations and problems.  We were forced to conclude that currently there is no single definitive method for computing ages in SAS.  If you need to compute ages in SAS, the best you can do is to choose the one that has the fewest problems for your particular situation.  After much debate, Lora Delwiche and I felt that we had no choice but to simply remove YRDIF from our book.

As a result of all this, we have written a paper, “Computing Ages in SAS: The Removal of the YRDIF Function from The Little SAS Book: A Primer, Fourth Edition.”  This paper explains how YRDIF really works, and then discusses alternate methods for computing ages. You can download this paper by clicking here.

Save 25% on The Little SAS Book Series through June 30, 2010

In Enterprise Guide, Everything, Little SAS Book Series, Publishing, SAS on June 22, 2010 at 7:05 am

The Little SAS Book series is on sale 25% off through June 30, 2010.
To order online:
1) Go to support.sas.com/bookstore.
2) Add books to cart and proceed to the checkout.
3) On the checkout page type the following in the comment field at the bottom. “LSBSeries25″
4) Final pricing, including taxes, shipping, promotional discounts will be reflected in your confirmation e-mail.

Here is what reviewers say about these books:

The Little SAS Book for Enterprise Guide 4.2

“It may be a ‘Little Book,’ but I was amazed at how much information about SAS Enterprise Guide 4.2 is included. The tutorials successfully take the reader on a journey covering all the main topics; then the reference section expands on these topics. I’ve been using SAS Enterprise Guide since version 1.1, but while reading this book I was reminded frequently of features that I ought to use more. It has something for everyone!”
Review by Philip R. Holland, Consultant and Author, Holland Numerics Ltd.

The Little SAS Book: A Primer, Fourth Edition

“The Fourth Edition of The Little SAS Book is not only an excellent primer for new SAS users, but it is also a great reference and update for experienced SAS users. The content provides a comprehensive overview of the SAS System in general, and data integration, manipulation, analysis, and reporting within SAS.”
Review by Systems Seminar Consultants, a SAS training and consulting company based in Madison, WI. Click here to read the complete review.

The Truth About What Motivates Us

In Sacramento Valley SAS Users Group, SAS Global Forum, Western Users of SAS Software, Detritus, SAS, Everything on June 2, 2010 at 8:40 am

What motivates you? When I was a kid, I used to play a board game called Careers.  In this game players moved around the board collecting points in three areas: fame , $ fortune, and happiness. The first player to achieve his chosen combination of points won the game.  It was a fun game, but I used to scratch my head at the idea that success in life could be reduced to a linear formula consisting of fame, fortune, and happiness.  (Yes, even as a ten-year-old, this seemed to me a pretty vacant idea of what life was about.)

When I was in graduate school, I heard about research showing that money can have a seemingly paradoxical effect on people.  Paying people lots of money can actually reduce their motivation rather than increase it.  What I didn’t know is that research on this topic has been ongoing.  Then my son (Elliott Slaughter, Computer Sci. and Eng. major at UCSD and open source developer) sent me the link to a fascinating talk by writer Dan Pink.  His talk is cleverly illustrated by RSA Animate.

So what does this have to do with SAS? Have you ever thought how amazing it is that we have local, regional, and international SAS user group meetings organized and executed primarily by volunteers?  Why are so many people willing to work hundreds of hours without being paid a cent year after year after year?  Pink explains why money is such a poor motivator, and what people really want.  He uses open source software as his example, but you could easily substitute SAS users groups.

Take 10 min. to watch Pink’s video Drive: The Surprising Truth About What Motivates Us.  I think you’ll be glad you did.

Follow

Get every new post delivered to your Inbox.