Hello,
I want to remove the duplicates and keep the line with the most recent month (comois).
If possible in sql
Data:
COMOIS | seg_cice | LIPRLG | COMAX |
202003 | JEUNE | client Jeune inactif | 205127 |
202011 | JEUNE | client Jeune inactif | 205127 |
202003 | 344978 | ||
202002 | JA/A/P | client Adulte inactif | 347109 |
202006 | JA/A/P | client Adulte inactif | 347109 |
202007 | JA/A/P | client Adulte inactif | 405866 |
202007 | JA/A/P | client Adulte inactif | 405868 |
202009 | JA/A/P | client Adulte inactif | 405868 |
202003 | 438218 | ||
202006 | 438218 | ||
202005 | JA/A/P | client Adulte inactif | 576036 |
202007 | JA/A/P | client Adulte inactif | 576036 |
202003 | JEUNE | client Jeune inactif | 626848 |
202012 | JEUNE | client Jeune inactif | 626848 |
202009 | JEUNE | client Jeune actif non équipé | 639972 |
202006 | JEUNE | client Jeune inactif | 646960 |
202012 | JEUNE | client Jeune inactif | 646960 |
Want:
COMOIS | seg_cice | LIPRLG | COMAX |
202003 | JEUNE | client Jeune inactif | 205127 |
202003 | 344978 | ||
202002 | JA/A/P | client Adulte inactif | 347109 |
202007 | JA/A/P | client Adulte inactif | 405866 |
202007 | JA/A/P | client Adulte inactif | 405868 |
202003 | 438218 | ||
202005 | JA/A/P | client Adulte inactif | 576036 |
202003 | JEUNE | client Jeune inactif | 626848 |
202009 | JEUNE | client Jeune actif non équipé | 639972 |
202006 | JEUNE | client Jeune inactif | 646960 |
Thanks for your help
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;
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;
Hi,
thanks for sharing the solution, I'm search for duplicate case, to make my company data is clean
best regards
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.