11-26-2012 03:14 PM
I have used the sum function in a data step to add the value of a previous row to a current one. I was wondering if there is something similar for subtracting a value in a previous row from a value in the current data set? I did not see anything for 'subtract' and tried adding a negative value using the sum function but that did not work either:
by cnty_name startyear agecat4 exitMonthCategory;
if first.agecat4 then CumulativeNumber=OutOfHomeCare;
OutOfHomeCare + (-CumulativeNumber);
11-26-2012 03:19 PM
The DIF (var) function, similar to LAG in concept, will give the difference from the previous record and the current or up to 99 records for a variable depending on DIF, DIF2, ..., DIF99. However you don't want to use it after IF statements as you will likely get unexpected results.
11-26-2012 05:09 PM
Paul, Depends upon what you need. I didn't even see the part of your post concerning previous record. Since the sum function retains a value across records, it could be used to start with a value and then subtract a current record's value from it. The dif function would just get the difference between the current and previous record.
Need further help from the community? Please ask a new question.