Search code examples
sqlsas

Getting the last day of month given a specific datetime variable in SAS EG


How do I get the last day of the month given a datetime variable like:

29DEC2022:00:00:00.000000

I want to convert the variable to: 31DEC2023:00:00:00.000000

And get a similar result if I input the datetime variable: 15DEC2022:00:00:00.000000

I hope you can help me in the right direction


Solution

  • It is unclear if you want a date or datatime result. This gives datetime.

    37         data _null_;
    38           x = '29DEC2022:00:00:00.000000'dt;
    39           l = intnx('DTMONTH',x,0,'E');
    40           put (x l)(=datetime.);
    41         run;
        
    x=29DEC22:00:00:00 l=31DEC22:23:59:59