BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mkeintz
PROC Star

The "then start_date=date" is correct.

 

The "if first.client and first.date" condition would be wrong, because:

  1. There is no BY statement to even generate the first.client and first.date dummy variables
  2. Even if there were, the condition ("first.client and first.date") would select EVERY observation from a daily file.
    1. But a "first.client" alone would work, although it's overkill.

 

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

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Astounding
PROC Star

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 16 replies
  • 3423 views
  • 1 like
  • 7 in conversation