Thank you very much for your help. I have found a solution that seems to be working as SELECT DISTINCT data_sinistro, identificativo_veicolo,
ifc(compress(identificativo_veicolo_denuncian,"* ")<compress(identificativo_veicolo_contropar,"* "),compress(identificativo_veicolo_denuncian,"* "),compress(identificativo_veicolo_contropar,"* ")) as targa1,
ifc(compress(identificativo_veicolo_denuncian,"* ")>compress(identificativo_veicolo_contropar,"* "),compress(identificativo_veicolo_denuncian,"* "),compress(identificativo_veicolo_contropar,"* ")) as targa2,
CASE WHEN ruolo_veicolo_richiesto = 'D' THEN 'D'
ELSE 'C' END AS ruolo_veicolo_richiesto,
'NO_CARD' AS tipo
FROM Ssrc
WHERE calculated targa1 NOT IN ('','ZZ999ZZ', 'ZZ999XX', 'ZZ99999', 'ZZ000ZZ', 'XXXXXX', 'AA00000', 'AA000AA', 'AA000BB', 'AA000XX', 'AA11111', 'AA000ZZ', 'AA111BB', 'XX000XX', 'ELIMINAT', 'XX999XX', 'XX111XX', 'XX123XX', 'MI111111', 'PLPENPLP', 'XX000YY', 'RMZ94732', 'AA111AA', 'AA123BB', 'BS400BZ', 'KASKO', 'RCDIV','VARIE','TRASP','PEDONE','MOTVEL','FURTOT','FURTOP','IGNOTO','INCEND','FURTOR','AGG.TO','ESTERA','FURTOL')
AND calculated targa2 NOT IN ('','ZZ999ZZ', 'ZZ999XX', 'ZZ99999', 'ZZ000ZZ', 'XXXXXX', 'AA00000', 'AA000AA', 'AA000BB', 'AA000XX', 'AA11111', 'AA000ZZ', 'AA111BB', 'XX000XX', 'ELIMINAT', 'XX999XX', 'XX111XX', 'XX123XX', 'MI111111', 'PLPENPLP', 'XX000YY', 'RMZ94732', 'AA111AA', 'AA123BB', 'BS400BZ', 'KASKO', 'RCDIV','VARIE','TRASP','PEDONE','MOTVEL','FURTOT','FURTOP','IGNOTO','INCEND','FURTOR','AGG.TO','ESTERA','FURTOL')
AND data_sinistro is not missing); Now one last step. In PostgreSQL I would run the following code: CREATE TABLE prova AS
SELECT DISTINCT ON (data_sinistro, identificativo_veicolo, targa1, targa2)
data_sinistro, identificativo_veicolo, targa1, targa2, ruolo_veicolo_richiesto, tipo
FROM (****) Where the **** represents the block of code previously written. This codes eliminates duplicates based on this three fields only (data_sinistro, identificativo_veicolo, targa1, targa2) Keeping all the variables data_sinistro, identificativo_veicolo, targa1, targa2, ruolo_veicolo_richiesto, tipo In the final table. Is there something similar in SAS? Thank you very much indeed for your help
... View more