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

Hello,

I want to remove the duplicates and keep the line with the most recent month (comois).

If possible in sql

                         

 

Data: 

 

COMOISseg_ciceLIPRLGCOMAX
202003JEUNEclient Jeune inactif205127
202011JEUNEclient Jeune inactif205127
202003  344978
202002JA/A/Pclient Adulte inactif347109
202006JA/A/Pclient Adulte inactif347109
202007JA/A/Pclient Adulte inactif405866
202007JA/A/Pclient Adulte inactif405868
202009JA/A/Pclient Adulte inactif405868
202003  438218
202006  438218
202005JA/A/Pclient Adulte inactif576036
202007JA/A/Pclient Adulte inactif576036
202003JEUNEclient Jeune inactif626848
202012JEUNEclient Jeune inactif626848
202009JEUNEclient Jeune actif non équipé639972
202006JEUNEclient Jeune inactif646960
202012JEUNEclient Jeune inactif646960

 

 

Want:

 

 

COMOISseg_ciceLIPRLGCOMAX
202003JEUNEclient Jeune inactif205127
202003  344978
202002JA/A/Pclient Adulte inactif347109
202007JA/A/Pclient Adulte inactif405866
202007JA/A/Pclient Adulte inactif405868
202003  438218
202005JA/A/Pclient Adulte inactif576036
202003JEUNEclient Jeune inactif626848
202009JEUNEclient Jeune actif non équipé639972
202006JEUNEclient Jeune inactif646960

 

 

Thanks for your help                                                  

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

SQL:

proc sql;
create table want as
  select *
  from have
  group by comax
  having comois = max(comois)
;
quit;

Data step, will perform much better on already sorted datasets (and needs less typing):

data want;
set have;
by comax;
if last.comax;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

SQL:

proc sql;
create table want as
  select *
  from have
  group by comax
  having comois = max(comois)
;
quit;

Data step, will perform much better on already sorted datasets (and needs less typing):

data want;
set have;
by comax;
if last.comax;
run;
gunturhakim
Calcite | Level 5

Hi,

thanks for sharing the solution, I'm search for duplicate case, to make my company data is clean

best regards

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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