The "then start_date=date" is correct.
The "if first.client and first.date" condition would be wrong, because:
What I meant was
"if _N_=1 then start_date=date;"
placed in front of the do group. The automatic variable _N_ counts the current iteration number in the DATA step. In this sample _N_ is tracking the number of MERGE actions (once for each incoming observation). So _N_=1 is the first observation.
. It selects the first record for a givne client/date - which means every record in your daily file.
Now "if first.client" would work, but is a sligh
As a rule, I find it easier to handle this type of problem in two steps instead of one. First, find the groupings:
data temp;
set have;
by client;
if first.client or dif(date) ne 1 then group + 1;
run;
Then find the endpoints:
proc summary data=temp;
by client group;
var date;
output out=want (keep=client start_date end_date) min=start_date max=end_date;
run;
************ EDITED:
sorry, didn't notice a very similar solution. However, notice that this condition is not sufficient:
date-lagdate>1
If one client started earlier than the previous client, the value for that expression could be negative.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.