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

I have a data set like this :

ID      NAME      BEGIN               END

345   CARL      16MAR2017     31MAR2017

345   CARL      03APR2017      30APR2017

120   ROSA      01JAN2017    14FEB2017

120   ROSA      02DEC2016      31DEC2016

 

How can I delete occurence but taking the most recent date ? I mean get some thing like this :

ID      NAME      BEGIN               END

345   CARL      03APR2017      30APR2017

120   ROSA      01JAN2017    14FEB2017

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

SAS can handle this easily enough, but the solution in part depends on whether your BEGIN and END variables are valid SAS dates vs. whether they are character strings.  PROC CONTENTS will tell you that.  If they are valid SAS dates:

 

proc sort data=have;

by id begin;

run;

 

data want;

set have;

by id begin;

if last.id;

run;

 

If your dates are actually character strings, does "JANV" actually appear in your data, or is that supposed to be "JAN"?  If there are invalid dates (which would include "JANV") they would need to be fixed first.  Then ...

 

data want;

set have;

begin_sasdate = input(begin, date9.);

end_sasdate = input(end, date9.);

format begin_sasdate end_sasdate date9.;

run;

 

proc sort data=want;

by id begin_sasdate;

run;

 

data want;

set want;

by id begin_sasdate;

if last.id;

run;

 

It's the same approach, but this approach requires that your data contain SAS dates, not character strings.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

SAS can handle this easily enough, but the solution in part depends on whether your BEGIN and END variables are valid SAS dates vs. whether they are character strings.  PROC CONTENTS will tell you that.  If they are valid SAS dates:

 

proc sort data=have;

by id begin;

run;

 

data want;

set have;

by id begin;

if last.id;

run;

 

If your dates are actually character strings, does "JANV" actually appear in your data, or is that supposed to be "JAN"?  If there are invalid dates (which would include "JANV") they would need to be fixed first.  Then ...

 

data want;

set have;

begin_sasdate = input(begin, date9.);

end_sasdate = input(end, date9.);

format begin_sasdate end_sasdate date9.;

run;

 

proc sort data=want;

by id begin_sasdate;

run;

 

data want;

set want;

by id begin_sasdate;

if last.id;

run;

 

It's the same approach, but this approach requires that your data contain SAS dates, not character strings.

John4
Obsidian | Level 7

yes its valid date (I edit the topic, its JAN instead of JANV)

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1034 views
  • 1 like
  • 2 in conversation