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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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