1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
options missing=0;
/************************ Traitements des tables issues des 8 conditions de sélection des clients en doubles ********************************/
%MACRO traitement_ajout_cpt (lib=, tab=);
/*SUPPRESSION DES DOUBLONS*/
proc sort data=&lib..&tab. nodupkey out=&tab.;
by no_seq_cli no_seq_cli1;
run;
/*VERIFICATION DE PRESENCE DE DOUBLON PAR CLIENT DANS L'OPTIQUE DE LA FUSION*/
proc sort data=&tab. nodupkey out=t_&tab.(keep=no_seq_cli SOURCE_CDT) ;
by no_seq_cli;
run;
/*FUSION*/
data t2_&tab.(keep=no_seq_cli1 /*compteur*/ SOURCE_CDT rename=(no_seq_cli1=no_seq_cli));
merge t_&tab.(in=a)
&tab.(in=b);
by no_seq_cli;
if a and b;
if no_seq_cli = no_seq_cli1 then delete;
run;
/*FUSION TABLES POUR APPARIEMENT DES COUPLES*/
PROC SQL;
CREATE TABLE WORK.APPEND_&tab. AS
SELECT * FROM WORK.t_&tab.
OUTER UNION CORR
SELECT * FROM WORK.t2_&tab.
;
Quit;
PROC SQL;
CREATE TABLE WORK.F_&tab. AS
SELECT t1.NO_SEQ_CLI LABEL="NO_SEQ_CLI_BEN" AS NO_SEQ_CLI_BEN,
t1.SOURCE_CDT
FROM WORK.APPEND_&tab. t1
ORDER BY t1.NO_SEQ_CLI;
QUIT;
PROC DATASETS lib=work nolist;
DELETE &tab. t_&tab. t2_&tab. APPEND_&tab.;
RUN;
PROC SORT DATA=F_&tab. (rename=SOURCE_CDT=CDT_&tab.);
BY NO_SEQ_CLI_BEN;
RUN;
%MEND;
%traitement_ajout_cpt(lib=sortie, tab=clipot_egal);
%traitement_ajout_cpt(lib=sortie, tab=clipot_soundex);
%traitement_ajout_cpt(lib=sortie, tab=clipot_difference);
%traitement_ajout_cpt(lib=sortie, tab=clipot_inclusion);
%traitement_ajout_cpt(lib=sortie, tab=clipot_inversion);
%traitement_ajout_cpt(lib=sortie, tab=clipot_appellation);
%traitement_ajout_cpt(lib=sortie, tab=clipot_sexediff);
%traitement_ajout_cpt(lib=sortie, tab=clipot_ncinverse);
/*CRÉATION DE L'INDICATEUR QUI SOULIGNE LA ou LES CONDITION DE DÉTECTION*/
data CDT_CLIPOT_DREAP(keep=NO_SEQ_CLI_BEN CDT_DETECTION);
merge F_CLIPOT_EGAL (in=a)
F_CLIPOT_SOUNDEX (in=b)
F_CLIPOT_DIFFERENCE (in=c)
F_CLIPOT_INCLUSION (in=d)
F_CLIPOT_INVERSION (in=e)
F_CLIPOT_APPELLATION(in=f)
F_CLIPOT_SEXEDIFF (in=g)
F_CLIPOT_NCINVERSE (in=h);
by no_seq_cli_ben ;
cdt_detection=compbl(CDT_clipot_egal !! " " !! CDT_clipot_soundex !! " " !! CDT_clipot_difference !! " " !!
CDT_clipot_inclusion !! " " !! CDT_clipot_inversion !! " " !! CDT_clipot_appellation
!! " " !! CDT_clipot_sexediff!! " " !! CDT_clipot_ncinverse );
RUN;
proc sort data=CDT_CLIPOT_DREAP nodupkey out=SORTIE.CDT_CLIPOT_DREAP ;
by no_seq_cli_ben cdt_detection;
run;
/*CRÉATION D'UNE TABLE UNIQUE DRÉAP PAR FUSION DES 8 TABLES*/
proc sort data=sortie.clipot_egal nodupkey out=EGAL(keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
proc sort data=sortie.clipot_SOUNDEX nodupkey out=SOUNDEX(keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
proc sort data=sortie.clipot_DIFFERENCE nodupkey out=DIFFERENCE(keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
proc sort data=sortie.clipot_INCLUSION nodupkey out=INCLUSION(keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
proc sort data=sortie.clipot_INVERSION nodupkey out=INVERSION (keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
proc sort data=sortie.clipot_APPELLATION nodupkey out=APPELLATION (keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
proc sort data=sortie.clipot_SEXEDIFF nodupkey out=SEXEDIFF (keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
proc sort data=sortie.clipot_NCINVERSE nodupkey out=NCINVERSE (keep=NO_SEQ_CLI NO_SEQ_CLI1 );
by no_seq_cli no_seq_cli1;
run;
/*FUSION DE LA TABLE: ELLE RERESENTE CHACUN DES COUPLES DE CLIPOT*/
data FUS_CLIPOT_DREAP (keep=NO_SEQ_CLI NO_SEQ_CLI1 );
merge EGAL (in=a)
SOUNDEX (in=b)
DIFFERENCE (in=c)
INCLUSION (in=d)
INVERSION (in=e)
APPELLATION (in=f)
SEXEDIFF (in=g)
NCINVERSE (in=h);
by NO_SEQ_CLI NO_SEQ_CLI1 ;
RUN;
/*SUPPRESSION DES DOUBLONS*/
proc sort data=FUS_CLIPOT_DREAP nodupkey out=FUS_CLIPOT_DREAP;
by no_seq_cli no_seq_cli1;
run;
/*TRAITEMENT HASH ---- APPARIEMENT DES FAMILLES*/
DATA TABLE_POUR_HASH;
SET FUS_CLIPOT_DREAP;
length PseudoFamille 8. ;
PseudoFamille=STRIP(_n_);
Rename no_seq_cli=IdClient1;
Rename no_seq_cli1=IdClient2;
run;
DATA PseudoFamille;
SET TABLE_POUR_HASH;
Length IdClient 8.;
IdClient=IdClient1;OUTPUT;
IdClient=IdClient2;OUTPUT;
KEEP IdCLient PseudoFamille;
run;
DATA _null_;
SET pseudoFamille end=eof;
length VFamille 8. ;
IF _n_=1 then do;
DECLARE HASH Client (DATASET:"PseudoFamille",multidata:"YES");
Client.DefineKey("IdClient" );
Client.DefineData("IdCLient",'PseudoFamille');
Client.DefineDone();
DECLARE HASH PSF (DATASET:"PseudoFamille",multidata:"YES");
PSF.DefineKey("PseudoFamille" );
PSF.DefineData("PseudoFamille","IdClient");
PSF.DefineDone();
DECLARE HASH LISTE (multidata:"NO");
LISTE = _NEW_ HASH();
LISTE.DefineKey('PseudoFamille');
LISTE.DefineDone();
DECLARE HITER HLISTE("LISTE");
DECLARE HASH NFAM (multidata:"NO");
NFAM = _NEW_ HASH();
NFAM.DefineKey('IdClient');
NFAM.DefineData('IdCLient','VFamille');
NFAM.DefineDone();
DECLARE HITER HNFAM("NFAM");
DECLARE HASH FAMILLE (multidata:"NO");
FAMILLE = _NEW_ HASH();
FAMILLE.DefineKey('IdClient');
FAMILLE.DefineData("IdClient","VFamille");
FAMILLE.DefineDone();
end;
RC_FAMILLE=FAMILLE.FIND();
IF RC_FAMILLE^=0 THEN DO; /***si RC_Famille^=0 on a trouvé un chef de famille ***/
RC_NFam=NFam.Clear();
RC_Liste=Liste.Clear();
VFamille=PseudoFamille; /** l'identifiant de famille est le premier identifiant de pseudofamille du chef de famille **/
RC_NFAM=NFAM.ADD(); /** le chef de famille est le premier individu de sa famille **/
Test=1;
DO UNTIL (Test=0);
Test1=0;Test2=0;
RC_HNFAM=HNFAM.First();
DO UNTIL (RC_HNFAM^=0);
RC_Client=Client.Find();
DO UNTIL (RC_Client^=0);
RC_Liste=Liste.Find();
IF RC_Liste^=0 THEN DO;RC_Liste=Liste.ADD(); Test1=1;END;
RC_Client=Client.Find_Next();
END;
RC_HNFAM=HNFAM.Next();
END;
RC_HListe=HListe.First();
DO UNTIL (RC_HListe^=0);
RC_PSF=PSF.Find();
DO UNTIL (RC_PSF^=0);
RC_NFAM=NFAM.Find();
IF RC_NFAM^=0 THEN DO;RC_NFAM=NFAM.ADD();Test2=1;END;
RC_PSF=PSF.Find_Next();
END;
RC_HListe=HListe.Next();
END;
test=MAX(test1,test2);
END;
RC_HNFAM=HNFAM.First();
DO UNTIL (RC_HNFAM^=0);
RC_FAMILLE=FAMILLE.ADD();
RC_HNFAM=HNFAM.Next();
END;
END;
IF eof then RC=FAMILLE.OUTPUT(dataset:'FAMILLE');
run;
proc sort DATA=famille;
by VFamille;
run;
/*******************************VERIFIER QUE LE RESULTAT EST 0 OBSERVATIONS****************************************/
proc sql;
create table Compteurs_restants as select
distinct a.*,
count (VFamille) as test_ID
from famille as a
group by VFamille
Having test_ID=1;
Quit;
/*TABLE DREAP FINAL*/
proc sql;
create table sortie.clipot_dreap as select
distinct a.IDclient as NO_SEQ_CLI_BEN,
a.VFamille AS compteur_dreap,
count (VFamille) as Nombre_occurence_cpt,
1 as DREAP
from famille as a
group by VFamille;
Quit;
/* SUPPRESSION DES TABLES INUTILES POUR LA SUITE*/
PROC DATASETS lib=work nolist;
DELETE CDT_CLIPOT_DREAP
EGAL SOUNDEX DIFFERENCE INCLUSION INVERSION APPELLATION SEXEDIFF NCINVERSE
F_CLIPOT_EGAL F_CLIPOT_SOUNDEX F_CLIPOT_DIFFERENCE F_CLIPOT_INVERSION
F_CLIPOT_INCLUSION F_CLIPOT_APPELLATION F_CLIPOT_SEXEDIFF F_CLIPOT_NCINVERSE
F_CLIPOT_DREAP_SEL F_CLIPOT_DREAP_FREQSSDOUB F_CLIPOT_DREAP_FREQ doublons
;
RUN; |
Partager