[ Retour aux Travaux Dirigés de SAS ]
/* Statistiques avec SAS, Corrigé du TD 1 */
/* Jean-Sebastien Roy (js@jeannot.org), 2000 */
%let chemin=//diamant/Data Mi2/sas/stats;
/* Definition de la Library 'tables' */
libname tables "&chemin/tables";
/* Liste des/de la table(s) */
proc datasets tables;
quit;
/* Contenu de la table */
proc contents tables.Q0;
run;
/* Quelques statistiques sur Q0 */
proc univariate tables.q0;
var q0;
run;
/* Petit graphique */
proc gplot tables.q0;
plot q0*dtu;
run;
quit;
/* Creation d'un variable DATE dans la table q0 */
data q0_1;
set tables.q0;
datepart(dtu); /* La date sans l'heure */
format date ddmmyy10.;
run;
/* Moyenne de q0 par jour */
proc summary q0_1 ;
by date;
var q0;
output q0_date(_type_ _freq_) ;
run;
/* Re-Petit graphique */
proc gplot q0_date;
plot q0*date;
run;
quit;
/* Creation d'une variable jour de la semaine dans q0_date */
data q0_date1;
set q0_date;
wday=weekday(date); /* Le jour de la semaine : 1=Dimanche */
run;
/* Re-Petit graphique */
proc gplot q0_date1;
where wday not in (1,7); /* On elimine les samedi et les dimanches */
plot q0*date;
run;
quit;
/* Lecture du fichier calendrier */
/*
Spécification :
00000000011111111112
12345678901234567890
AAMMDDd c
AA : l'année (si AA<60 alors l'année est 20AA sinon 19AA)
MM : le mois
DD : le jour
d : Alternativement 1 ou 2. Les lignes sont répétées deux fois.
c : CDAY
CDAY:
4=Jour Ferié
5=Lendemain de JF
3=Lundi normal
0=Mardi-Vendredi normal
1=Samedi normal
2=Dimanche normal
7=Veille de JF
9=Invalide
*/
data cal0;
length cday $ 1;
infile "&chemin/infiles/Angleterre";
input aa 11-12 mm 13-14 dd 15-16 demi 17 cday $ 20;
if demi=1;
if aa<60 then aa=aa+2000;
else aa=aa+1900;
mdy(mm,dd,aa);
format date ddmmyy10.;
keep date cday;
run;
/* Creation d'une variable type de jour (TDAY) dans le calendrier */
data cal;
set cal0;
length tday $ 1;
wday=weekday(date); /* Le jour de la semaine : 1=Dimanche */
if wday=1 then tday='D'; /* dimanche */
else if wday=2 then tday='L'; /* lundi */
else if wday=6 then tday='V'; /* vendredi */
else if wday=7 then tday='S'; /* samedi */
else tday='O'; /* autres */
if cday='4' then tday='D'; /* Jour férié -> Dimanche */
else if cday='5' then do; /* Lend. de JF */
if tday='O' then tday='L'; /* Autres -> Lundi */
else if tday='S' then tday='D'; /* Samedi -> Dimanche */
end;
else if cday='7' and tday='O' then tday='V'; /* Veille de JF -> Vendredi */
keep date wday cday tday;
run;
/* Lien Q0_DATE <-> Calendrier */
data q0_date2;
merge q0_date ( inq0)
cal ( incal);
by date;
if inq0 and incal; /* Informations présentes dans les deux tables seulement*/
run;
/* Re-Petit graphique */
proc gplot q0_date2;
where tday='O';
plot q0*date;
run;
quit;