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
| %macro Plotacp(DATA= ,AXEH= ,AXEV= ,COND= ,CERCLE=N,BAREA=N)/ STORE DES="Réprésentation des individus et variable en ACP";/*Je dupplique la table dans une autre _Graph en supprimant les données manquantes*/
DATA _Graph_;
set &DATA;
if not Missing(coord1);
run;
/*J'applique la condition. les observations et les variables que je veux afficher*/
DATA _Graph_;
SET _Graph_;
%if %length(&COND)^=0 %then;
&COND;
%end;
run;
/*Construction de la table Annotate*/
data ACPANNOT;
length function $10.;
set _Graph_;
function="Label";
run;
data ACPANNOT;
length color $10.;
length text $10.;
set ACPANNOT;
/*Les noms à écrire pour les observations et les variables dans le graphique*/
text=_LABEL_;
position="3";
x=coord&AXEH;
y=coord&AXEV;
xsys='2';
ysys='2';
if _TYPE_="OBSACT" then color="purple";
else if _TYPE_="OBSSUP" then color="black";
else if _TYPE_="VARACT" then color="blue";
else color="red";
if _TYPE_="OBSSUP" then size=1.7;
else size=0.9;
Output;
/*Pour tracer les segments des variables. Les segments sont tracées du centre du cercle vers les points*/
if _TYPE_ IN ("VARACT","VARSUP") then do;
x=0;
y=0;
function="Move";
if _TYPE_="OBSACT" then color="blue";
else if _TYPE_="OBSSUP" then color="red";
else if _TYPE_="VARACT" then color="blue";
else color="red";
size=0.8;
when="B";
end;
output;
if _TYPE_ IN ("VARACT","VARSUP") then do;
x=coord&AXEH;
y=coord&AXEV;
function="Draw";
if _TYPE_="OBSACT" then color="blue";
else if _TYPE_="OBSSUP" then color="red";
else if _TYPE_="VARACT" then color="blue";
else color="red";
size=0.8;
when="A";
end;
output;
/*Pour mettre les symboles*/
function="Symbol";
position="5";
when="B";
x=coord&AXEH;
y=coord&AXEV;
xsys='2';
ysys='2';
if _TYPE_="OBSACT" then text="triangle";
else if _TYPE_="OBSSUP" then text="dot";
else if _TYPE_="VARACT" then text="circle";
else text="circle";
if _TYPE_="OBSACT" then size=0.01*(co2_&AXEH+co2_&AXEV);
else if _TYPE_="OBSSUP" then size=0.03*(co2_&AXEH+co2_&AXEV);
else if _TYPE_="VARACT" then size=0.035*(co2_&AXEH+co2_&AXEV);
else size=0.035*(co2_&AXEH+co2_&AXEV);
if _TYPE_="OBSACT" then color="purple";
else if _TYPE_="OBSSUP" then color="yellow";
else if _TYPE_="VARACT" then color="blue";
else color="red";
output;
run;
%if &CERCLE=O %then %do;
data ACPANNOT;
set ACPANNOT end=fin;
output ACPANNOT;
if fin then do;
x=1;
y=0;
function="Move";
color='black';
size=0.2;
when="A";
output;
do angle=0 to 44/7 by 0.01;
x=cos(angle);
y=sin(angle);
function="Draw";
When="A";
color='black';
output;
end;
output;
x=1;
y=0;
function="Draw";
color='black';
when="A";
output;
end;
run;
%end;
options nodate;
goptions reset=all gunit=pct htext=2;
%if &BAREA=O %then %do;
goptions hsize=6 vsize= 6;
%end;
%else %do;
goptions hsize=6 vsize= 6;
%end;
axis1 minor=none offset=(4,4) major=(h=0.1 w=1) label=("Axe&AXEH");
axis2 minor=none offset=(4,4) major=(h=0.1 w=1) label=("Axe&AXEV");
symbol v=none;
proc gplot data=ACPANNOT;
plot y*x=1/frame cframe=white href=0 vref=0 overlay annotate=ACPANNOT grid haxis=axis1 vaxis=axis2;
run;
quit;
proc datasets lib=Work memtype=Data nolist;
%if &CERCLE=O %then %do;
delete Acpannot Acpannotm Acpannotn _graph_;
%end;
run;
%Put Fin de macro;
%put Ecris moi si tu rencontres de difficultés: ariel92and@gmail.com;
%mend Plotacp; |
Partager