Search code examples
datesas

Flag rows in a SAS table dated from the previous 30 days


I have a dataset that uses dates, and I want to create two variables. One is to flag where the 'created_date' is from the last 30 days, and another to flag where the 'created_date' is from the previous 30 days. The 30 days flag works fine, but the I'm having issues with the previous 30 days. Here is my code:

if created_date >= intnx("day","&sysdate"d,-30,"same") then Flag_30D = 1; else Flag_30D = 0;
if created_date <= intnx("day","&sysdate"d,-30,"same") and created_date >= ("day","&sysdate"d,-60,"same") then Flag_P30D = 1; else Flag_P30D = 0;

Solution

  • You have a typo and left out INTNX in second part of if expression.

    created_date >= ("day","&sysdate"d,-60,"same")
    

    should be

    created_date >= INTNX("day","&sysdate"d,-60,"same")
                    ^^^^^