SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jaap_K
Calcite | Level 5

Hi,

I have a dataset that I want to split based on 2 date columns. In this new column, the date for the intervening months should become the last day of that month
Example;
Start date             Enddate
03Jan2022           05may2022

 

Result:

Start date             Enddate               NewColumn
03Jan2022           05may2022        03jan2022

03Jan2022           05may2022        28feb2022

03Jan2022           05may2022        31mar2022

03Jan2022           05may2022        30apr2022

03Jan2022           05may2022        05may2022

 

Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This solution assumes that the values of startdate and enddate are valid numeric SAS date values.

 

data have;
    startdate='03JAN2022'd;
    enddate='05MAY2022'd;
run;
data want;
    set have;
    diff_months=intck('month',startdate,enddate);
    do i=0 to diff_months;
        if i=0 then newcolumn=startdate;
        else if i=diff_months then newcolumn=enddate;
        else newcolumn=intnx('month',startdate,i,'e');
        output;
    end;
    drop i diff_months;
    format newcolumn date9.;
run;
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

This solution assumes that the values of startdate and enddate are valid numeric SAS date values.

 

data have;
    startdate='03JAN2022'd;
    enddate='05MAY2022'd;
run;
data want;
    set have;
    diff_months=intck('month',startdate,enddate);
    do i=0 to diff_months;
        if i=0 then newcolumn=startdate;
        else if i=diff_months then newcolumn=enddate;
        else newcolumn=intnx('month',startdate,i,'e');
        output;
    end;
    drop i diff_months;
    format newcolumn date9.;
run;
--
Paige Miller

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 712 views
  • 0 likes
  • 2 in conversation