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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: