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.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 16 replies
  • 1260 views
  • 1 like
  • 7 in conversation