How do I get the second last date in proc sql?

Viewed 23

I'm writing a query in SQL to get the First, Last and Second last Transaction date for Customers. I have added the first and last using the Min() and Max() functions, how can I add the second last date in my query?

select distinct Shoppers,  Min(Date) as First_Txn, Max(Date) as Last_Txn, 
        sum(revenue_sale) as Revenue, sum(units) as Units, count(distinct invoice) as Invoices, 
            from myTable
                where Date between 20220101 and 20220131
            group by 1;
0 Answers
Related