[ Retour aux Travaux Dirigés de SAS ]

/* Statistiques avec SAS, TD 2 : Lecture du calendrier (code réalisé lors du TD 1) */
/* Jean-Sebastien Roy (js@jeannot.org), 2000 */

/* Lecture du fichier calendrier */
/*
   Définir le filename 'cal' avant d'executer le code par :
   
   Filename cal "monCheminVersLeCalendrier";
   exemple :
   Filename cal "E:\sas\stats\Infiles\Angleterre";
*/


/*

Spécification du format de fichier :

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 cal;

  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;

  date=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;