0

I have a table of customers with effective and termination dates. Instead of having one record, I am trying to create a table that has one record per year & month for each month the member is active. Is there a simple way to create the desired table in SAS? FYI, the raw table will have a few thousand records, and will about a dozen columns, but wanted to keep the example simple for now. Also, there's no line in between the records in the desired table, just added for ease of reference. Thanks.

Raw and Desire Tables

enter image description here

Raw Table
Name Eff_date Term_Date
John 1/1/2020 3/31/2020
Amy 3/1/2019 3/10/2019

Desired Table
Name Eff_date Term_Date Eff_YM

John 1/1/2020 3/31/2020 202001

John 1/1/2020 3/31/2020 202002

John 1/1/2020 3/31/2020 202003

Amy 3/1/2019 3/10/2019 201903

1
  • 1
    Hi, welcome to the site. We're not a code writing service, but a code help services, so make sure your question includes a code problem and the attempt you've made to solve that problem, and specific questions about what you think is wrong or what you don't understand about the problem. See our faq and the help center for more information. Thanks, and welcome! Commented Nov 4, 2020 at 17:26

1 Answer 1

1
  • INTCK() will find the number of months between two dates

  • INTNX() will increment dates by a specified amount, ie 1 month, 1 week

  • An explicit OUTPUT statement will write a new line for each month

     data have;
     informat name $8. date_start date_end mmddyy10.;
     format name $8. date_start date_end mmddyy10.;
     input Name date_start date_end;
     cards;
     John 1/1/2020 3/31/2020
     Amy 3/1/2019 3/10/2019
     ;;;;
    run;
    
     data want;
     set have;
     nMonths=intck('month', date_start, date_end, 'C');
    
     do i=0 to nMonths;
         Effective_YM=intnx('month', date_start, i, 's');
         format effective_YM yymmn6.;
         OUTPUT;
     end;
     drop nMonths;
     run;
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.