BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jmmedina252
Fluorite | Level 6

Hi, I need to get a list of dates between an members start date and end date and the day count they would be.  The data looks like this:

Member   Start_date   End_date  

100          19MAY21     25MAY21

103          01MAY21     04MAY21

105          03MAY21     04MAY21

 

and the output data would be like this with all dates in between the start and end date per member:

 

Member   Start_date   End_date   Date           Date_Count

100          19MAY21     25MAY21   19MAY21   0

100          19MAY21     25MAY21   20MAY21   1

100          19MAY21     25MAY21   21MAY21   2

100          19MAY21     25MAY21   22MAY21   3

100          19MAY21     23MAY21   23MAY21   4

103          01MAY21     04MAY21   01MAY21   0

103          01MAY21     04MAY21   02MAY21   1

103          01MAY21     04MAY21   03MAY21   2

103          01MAY21     04MAY21   04MAY21   3

105          03MAY21     04MAY21   03MAY21   0

105          03MAY21     04MAY21   04MAY21   1

 

Note: Start_date is day 0

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10

Here's one way: Looping from start_date to end_date for each member, and outputting a new row each time.

data have;
    input member start_date :date9. end_date :date9.;
    format start_date end_date date9.;
    datalines;
100 19MAY21 25MAY21
103 01MAY21 04MAY21
105 03MAY21 04MAY21
run;

data want (drop=i);
    set have;
    by member;
    retain i 0;
    format date date9.;
    if first.member then i=0;
    date = start_date;
    do while (date < end_date);
        date = intnx('day',start_date,i);
        date_count = i;
        i = i+1;
        output;
    end;
run;

proc print; run;

Result:

Capture_20230421.PNG

View solution in original post

2 REPLIES 2
mklangley
Lapis Lazuli | Level 10

Here's one way: Looping from start_date to end_date for each member, and outputting a new row each time.

data have;
    input member start_date :date9. end_date :date9.;
    format start_date end_date date9.;
    datalines;
100 19MAY21 25MAY21
103 01MAY21 04MAY21
105 03MAY21 04MAY21
run;

data want (drop=i);
    set have;
    by member;
    retain i 0;
    format date date9.;
    if first.member then i=0;
    date = start_date;
    do while (date < end_date);
        date = intnx('day',start_date,i);
        date_count = i;
        i = i+1;
        output;
    end;
run;

proc print; run;

Result:

Capture_20230421.PNG

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 553 views
  • 4 likes
  • 3 in conversation