BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kbinan
Obsidian | Level 7

Hello SAS users!

I am trying to get a MIN and MAX date onto my data to enable the  creation of  a single record when I roll this up by CLM_NUM.  What I want is the earliest FST_SRVC_DT and the latest LST_SRVC_DT on all claim lines for a given CLM_NUM.

 

This is what I want it to look like:

 

CLM_NUMFST_SRVC_DTLST_SRVC_DTIP_STARTIP_END
756653xxXXX22Dec201824Dec201812/22/201812/31/2018
756653xxXXX25Dec201829Dec201812/22/201812/31/2018
756653xxXXX30Dec201831Dec201812/22/201812/31/2018

 

Data is previously sorted by CLM_NUM - what am I doing wrong?  I end up with only the last record looking like I want it to.

 

DATA WORK.want;

SET WORK.have;

BY CLM_NUM;

IF FIRST.CLM_NUM

THEN DO;

  IP_START = FST_SRVC_DT;

END;

 

ELSE IF LAST.CLM_NUM

THEN DO;

   IP_END = LST_SRVC_DT;

END;

RETAIN IP_START IP_END;

format IP_START MMDDYY10.;

format IP_END MMDDYY10.;

 

IP_START = MIN(IP_START,FST_SRVC_DT);

IP_END = MAX(IP_END,LST_SRVC_DT);

RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20


data have;
input CLM_NUM :$15.	(FST_SRVC_DT	LST_SRVC_DT) (:date9.);*	IP_START	IP_END ;
format 	FST_SRVC_DT	LST_SRVC_DT date9.;
cards;
756653xxXXX	22Dec2018	24Dec2018	12/22/2018	12/31/2018
756653xxXXX	25Dec2018	29Dec2018	12/22/2018	12/31/2018
756653xxXXX	30Dec2018	31Dec2018	12/22/2018	12/31/2018 
;

/*Datastep*/

data want;
 do _n_=1 by 1 until(last.CLM_NUM);
  set have;
  by CLM_NUM;
  IP_START=min(IP_START, FST_SRVC_DT);
  IP_END=max( IP_END,LST_SRVC_DT);
 end;
 do _n_=1 to _n_;
  set have;
  output;
 end;
 format  IP_START IP_END date9.;
run;

 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20


data have;
input CLM_NUM :$15.	(FST_SRVC_DT	LST_SRVC_DT) (:date9.);*	IP_START	IP_END ;
format 	FST_SRVC_DT	LST_SRVC_DT date9.;
cards;
756653xxXXX	22Dec2018	24Dec2018	12/22/2018	12/31/2018
756653xxXXX	25Dec2018	29Dec2018	12/22/2018	12/31/2018
756653xxXXX	30Dec2018	31Dec2018	12/22/2018	12/31/2018 
;

/*Datastep*/

data want;
 do _n_=1 by 1 until(last.CLM_NUM);
  set have;
  by CLM_NUM;
  IP_START=min(IP_START, FST_SRVC_DT);
  IP_END=max( IP_END,LST_SRVC_DT);
 end;
 do _n_=1 to _n_;
  set have;
  output;
 end;
 format  IP_START IP_END date9.;
run;

 
kbinan
Obsidian | Level 7

@

THANK YOU SO MUCH!  That worked perfectly!

novinosrin
Tourmaline | Level 20

On the other hand, Proc SQL autoremerge is very convenient 

 



data have;
input CLM_NUM :$15.	(FST_SRVC_DT	LST_SRVC_DT) (:date9.);*	IP_START	IP_END ;
format 	FST_SRVC_DT	LST_SRVC_DT date9.;
cards;
756653xxXXX	22Dec2018	24Dec2018	12/22/2018	12/31/2018
756653xxXXX	25Dec2018	29Dec2018	12/22/2018	12/31/2018
756653xxXXX	30Dec2018	31Dec2018	12/22/2018	12/31/2018 
;
/*Proc SQL*/

proc sql;
create table want as
select * ,min( FST_SRVC_DT) as 	IP_START format=date9.,max(	LST_SRVC_DT) as IP_END format=date9.
from have
group by CLM_NUM
order by CLM_NUM, FST_SRVC_DT;
quit;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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