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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.