Return to Archive

SAS Tip of the Month
December 2004

I was asked a short time ago why use the SAS SUM function when adding two numbers a simple arithmetic expression is possible? To give a simple answer it is the way SAS deals with a 'missing' value. To use an example the following timesheet data for a project is loaded using the following datastep and two variable TOT_SUM and TOT_ARITH are created:

    data TimeSheet;
        infile cards;
        input DAY $ 1-3 AM_HOURS 5-8 PM_HOURS 10-13;

The variable TOT_SUM is created from adding the variables AM_Hours and PM_Hours using the SUM function while the variable TOT_ARITH is created from the using an arithmetic expression. The following table shows the results:

    Day  AM_Hours  PM_Hours  Tot_Sum  Tot_Arith
    MON     3.5       4.5       8.0      8.0
    TUE      .        1.0       1.0       .
    WED     2.5        .        2.5       .
    THU      .         .         .        .
    FRI     2.0       3.0       5.0      5.0

From the table the variable TOT_SUM is correct as it considers the 'missing' value as a valid value in the expression.

Have a safe and happy holiday season.

Updated December 6, 2004