Help using Base SAS procedures

Expanding start and end dates

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Expanding start and end dates

Hello,

I'm currently trying to do what should be a simple task but the searches for proc expand and retain functions haven't been giving me the code that I need.

I currently have 3 columns, ID, Startdate, enddate, and I'd like to expand my dataset to fill in the months between my start and end dates.

For example:

ID          Startdate     Enddate

1           01/2001       03/2001

Would become:

ID          date

1          01/2001

1          02/2001

1          03/2001

Thanks.


Accepted Solutions
Solution
‎07-19-2012 04:10 PM
Contributor
Posts: 52

Re: Expanding start and end dates

I assume that startdate and enddate are both SAS dates in mmyys7. format:

data new (keep=id date);

   set old;

   format date mmyys7.;

   do increment = 0 to intck('month', startdate, enddate);

      date = intnx('month', startdate, increment, 'beginning');

      output;

   end;

run;

View solution in original post


All Replies
Solution
‎07-19-2012 04:10 PM
Contributor
Posts: 52

Re: Expanding start and end dates

I assume that startdate and enddate are both SAS dates in mmyys7. format:

data new (keep=id date);

   set old;

   format date mmyys7.;

   do increment = 0 to intck('month', startdate, enddate);

      date = intnx('month', startdate, increment, 'beginning');

      output;

   end;

run;

Occasional Contributor
Posts: 18

Re: Expanding start and end dates

Works exactly as I wanted! Thanks!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 570 views
  • 0 likes
  • 2 in conversation