IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SAS Base Discussion :

Selection dans une proc sql - compatibilité de format


Sujet :

SAS Base

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut Selection dans une proc sql - compatibilité de format
    Bonjour,
    J'ai un problème pour selectionner un élément d'une table: en effet la table en question s'appelle fem et contient une variable Age contenant des ages(entier) et des variables années du genre _900 _901 _902 .... jusqu'à _005 de type numerique (qui correspondent aux années au 1900 1901 ...2005).Toutes les variables sont en colonnes.
    J'ai une autre table toto, de laquelle je fais des extractions ligne par ligne pour avoir des sous tables tato_1 tato_2 ainsi de suite...afin d'effectuer des operations.
    Toutes les étapes data marchent sauf la dernière oû j'essaie de selectionner le nombre qui correspond à l'age Age et à l'année _919 par exemple.Je ne sais pas si c'est un prb de format...car &ane est type caractère alors que les variables années (_900 _901 ..) sont numeriques...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    %macro test;
    OPTION SPOOL;
    %DO i=1 %TO 2 %BY 1;
    Data tati_&i;/* extraction de la 1ère ligne */
    set lib.toto (firstobs=&i obs=&i);
    run;
    Data tato_&i; /* ajout d'une variable age dans tati */
    set tati_&i;
    age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    run;
    proc sql; /* pr select l'âge */
    select age INTO :age from tato_&i;
    quit;
     
    data tato_&i;/* pour juste ajouter l'annee de naissance*/
    set tato_&i;
    annee=YEAR(Date_naiss_rentier);
    run;
    data tato_&i; /* pour changer le type de annee en carac :)*/
    set tato_&i;
    an=PUT(annee,$4.);
    run;
    data tato_&i; /* pour extraire les 3 derniers chiffres de l'année de naiss */
    set tato_&i;
    an_=SUBSTR(an,2);
    run;
    data tato_&i; /* concatenation */
    set tato_&i;
    ane=CATS('_',an_);
    run;
    /* data tato_&i;    
     set tato_&i;                
    ani=INPUT(ane,4.);
    run;*/
    /* pour changer le type de annee  en numerique mais      ça ne marche pas
     car on a  _919  comme valeur de ane.*/
     
     
    proc sql; /* select du nbre de survivants à l'age 'age' c'est là le problème!!  je crois qu'il ne reconnait pas &ane */
    select &ane INTO:l&i from lib.fem tato_&i where Age=&age; 
    quit;
     
    %put l&i=&&l&i;
     %END;
     %mend test;
    %test;
    j'ai joint les tables tato_1 et 2 sous excel.Merci d'avance.
    Fichiers attachés Fichiers attachés

  2. #2
    Membre émérite

    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Mars 2005
    Messages
    1 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence
    Secteur : Conseil

    Informations forums :
    Inscription : Mars 2005
    Messages : 1 364
    Points : 2 329
    Points
    2 329
    Par défaut
    tu peux ajouter l'
    et exécuter le programme?

  3. #3
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut
    J'ai ajouté l'option mprint, il crée les sous tables tati_1 tati_2 tato_1 tato_2 mais il ne donne toujours pas la valeur de lx. (il y'avait l&i=&&l&i ds mon premier post, j'ai éssayé aussi avec l&i=&l&i, ça ne marche pas.. voici ce qu'il donne ds le log
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
                                                    49       49
    NOTE 49-169: La signification d'un identificateur après une chaîne entre guillemets peut changer dans une version SAS future. Il
                 est recommandé d'insérer un espace entre une chaîne entre guillemets et l'identificateur suivant.
    1107  select &ane INTO:l&i from lib.fem tato_&i where Age=&age;
    1108  quit;
    1109
    1110  %put l&i=&l&i;
    1111   %END;
    1112   %mend test;
    1113  %test;
    MPRINT(TEST):   OPTION mprint;
    MPRINT(TEST):   Data tati_1;
    MPRINT(TEST):   set lib.toto (firstobs=1 obs=1);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table LIB.TOTO.
    NOTE: La table WORK.TATI_1 a 1 observation(s) et 19 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.01 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   Data tato_1;
    MPRINT(TEST):   set tati_1;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATI_1.
    NOTE: La table WORK.TATO_1 a 1 observation(s) et 20 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_1;
    MPRINT(TEST):   quit;
    NOTE: Procédure SQL a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_1.
    NOTE: La table WORK.TATO_1 a 1 observation(s) et 21 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: La variable annee a déjà été définie comme numérique.
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_1.
    NOTE: La table WORK.TATO_1 a 1 observation(s) et 22 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.01 secondes
          temps UC            0.01 secondes
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_1.
    NOTE: La table WORK.TATO_1 a 1 observation(s) et 23 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_1.
    NOTE: La table WORK.TATO_1 a 1 observation(s) et 24 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   proc sql;
    NOTE 137-205: Ligne générée par la macro appelée "TEST".
    4      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    4   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                 ----
                                                                 22
    4   ! INTO:l&i from
    ERROR 22-322: Erreur de syntaxe ; syntaxe requise : une chaîne entre guillemets, !, !!, &, (, *, **, +, ',', -, '.', /, <, <=,
                  <>, =, >, >=, ?, AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS,
                  LABEL, LE, LEN, LENGTH, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.
     
    NOTE: Ligne générée par la macro appelée "TEST".
    4      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    4   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                                       ------
                                                                                       49
    4   ! INTO:l&i from
    NOTE 49-169: La signification d'un identificateur après une chaîne entre guillemets peut changer dans une version SAS future. Il
                 est recommandé d'insérer un espace entre une chaîne entre guillemets et l'identificateur suivant.
     
    NOTE: Ligne générée par la macro appelée "TEST".
    4      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    4   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                 ----
                                                                 76
    4   ! INTO:l&i from
    ERROR 76-322: Erreur de syntaxe ; l'instruction sera ignorée.
     
    NOTE: Ligne générée par la macro appelée "TEST".
    4      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    4   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                                                ----
                                                                                                49
    4   ! INTO:l&i from
    NOTE 49-169: La signification d'un identificateur après une chaîne entre guillemets peut changer dans une version SAS future. Il
                 est recommandé d'insérer un espace entre une chaîne entre guillemets et l'identificateur suivant.
     
    WARNING: Référence symbolique apparente ANE non traitée.
    MPRINT(TEST):   select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane INTO:l1 from lib.fem tato_1 where
    Age= 93;
    MPRINT(TEST):   quit;
    NOTE: Le Système SAS a interrompu le traitement de cette étape en raison d'erreurs.
    NOTE: Procédure SQL a utilisé (Durée totale du traitement) :
          temps réel          0.01 secondes
          temps UC            0.00 secondes
     
    WARNING: Référence symbolique apparente L non traitée.
    l1=&l1
     
     
    MPRINT(TEST):   Data tati_2;
    MPRINT(TEST):   set lib.toto (firstobs=2 obs=2);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table LIB.TOTO.
    NOTE: La table WORK.TATI_2 a 1 observation(s) et 19 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   Data tato_2;
    MPRINT(TEST):   set tati_2;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATI_2.
    NOTE: La table WORK.TATO_2 a 1 observation(s) et 20 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.01 secondes
          temps UC            0.01 secondes
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_2;
    MPRINT(TEST):   quit;
    NOTE: Procédure SQL a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_2.
    NOTE: La table WORK.TATO_2 a 1 observation(s) et 21 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: La variable annee a déjà été définie comme numérique.
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_2.
    NOTE: La table WORK.TATO_2 a 1 observation(s) et 22 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_2.
    NOTE: La table WORK.TATO_2 a 1 observation(s) et 23 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.01 secondes
          temps UC            0.01 secondes
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE:  1 observation(s) lue(s) dans la table WORK.TATO_2.
    NOTE: La table WORK.TATO_2 a 1 observation(s) et 24 variable(s).
    NOTE: L'étape DATA a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
     
    MPRINT(TEST):   proc sql;
    NOTE 137-205: Ligne générée par la macro appelée "TEST".
    8      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    8   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                 ----
                                                                 22
    8   ! INTO:l&i from
    ERROR 22-322: Erreur de syntaxe ; syntaxe requise : une chaîne entre guillemets, !, !!, &, (, *, **, +, ',', -, '.', /, <, <=,
                  <>, =, >, >=, ?, AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS,
                  LABEL, LE, LEN, LENGTH, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.
     
    NOTE: Ligne générée par la macro appelée "TEST".
    8      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    8   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                                       ------
                                                                                       49
    8   ! INTO:l&i from
    NOTE 49-169: La signification d'un identificateur après une chaîne entre guillemets peut changer dans une version SAS future. Il
                 est recommandé d'insérer un espace entre une chaîne entre guillemets et l'identificateur suivant.
     
    NOTE: Ligne générée par la macro appelée "TEST".
    8      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    8   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                 ----
                                                                 76
    8   ! INTO:l&i from
    ERROR 76-322: Erreur de syntaxe ; l'instruction sera ignorée.
     
    NOTE: Ligne générée par la macro appelée "TEST".
    8      tato_&i;  set tato_&i; an=PUT(annee,$4.); run; data tato_&i;  set tato_&i; an_=SUBSTR(an,2); run; data tato_&i;  set
    8   ! tato_&i; ane=CATS('_',an_); run;  proc sql;  select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane
                                                                                                ----
                                                                                                49
    8   ! INTO:l&i from
    NOTE 49-169: La signification d'un identificateur après une chaîne entre guillemets peut changer dans une version SAS future. Il
                 est recommandé d'insérer un espace entre une chaîne entre guillemets et l'identificateur suivant.
     
    WARNING: Référence symbolique apparente ANE non traitée.
    MPRINT(TEST):   select du nbre de survivants à l'age 'age' c'est là le problème!! select &ane INTO:l2 from lib.fem tato_2 where
    Age= 86;
    MPRINT(TEST):   quit;
    NOTE: Le Système SAS a interrompu le traitement de cette étape en raison d'erreurs.
    NOTE: Procédure SQL a utilisé (Durée totale du traitement) :
          temps réel          0.00 secondes
          temps UC            0.00 secondes
     
    WARNING: Référence symbolique apparente L non traitée.
    l2=&l2

  4. #4
    Membre émérite

    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Mars 2005
    Messages
    1 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence
    Secteur : Conseil

    Informations forums :
    Inscription : Mars 2005
    Messages : 1 364
    Points : 2 329
    Points
    2 329
    Par défaut
    il a l'air d'exécuté le commentaire /* select du nbre de survivants à l'age 'age' c'est là le problème!! je crois qu'il ne reconnait pas &ane */

    Tu peux le déplacer en dehors de la proc sql, et relancer?

  5. #5
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut
    j'ai supprimé le commentaite /*select du nbre de survivants à l'age 'age' c'est là le problème!! */ il fait toujours la mème chose..

  6. #6
    Rédacteur

    Homme Profil pro
    SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Inscrit en
    Avril 2009
    Messages
    2 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2009
    Messages : 2 497
    Points : 6 064
    Points
    6 064
    Par défaut
    il ne peut pas faire la même chose puisque tu as supprimé le commentaire. Où place-t-il l'erreur maintenant ?

    Pourquoi y a t il un blanc entre lib.fem et tato_&i dans ton FROM ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT &ane INTO:l&i FROM lib.fem tato_&i WHERE Age=&age;

  7. #7
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut
    Effectivement il ne signale plus d'erreur au niveau du commentaire, il créee correctement les tables intermediaires...mais il ne donne pas la valeur de la dernière proc sql l2=&l2 . Il ya espace entre lib.fem et tato_&i car ce sont deux tables differentes (au fait je veux selectionner le nombre de survivants ds la table fem à partir de l'année ( annee ds la table tato_&i que j'ai transformé en ane = _926) car dans la table fem les années sont definies comme suit :_900 _901 ...jusquà _005 (j'ai joint la table ci-dessus).
    Voici ce qu'il affiche ds le log après la suppression du commentaire.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    NOTE: Copyright (c) 2002 by SAS Institute Inc., Cary, NC, USA.
    NOTE: SAS (r) Proprietary Software Version 9.00 (TS M0)
          Licensed to SUNY AT STONY BROOK, Site 0013402001.
    NOTE: This session is executing on the XP_HOME  platform.
     
     
     
    NOTE: SAS initialization used:
          real time           8.94 seconds
          cpu time            0.71 seconds
     
    1    libname lib "P:\dossier_calcul\26_06" ;
    NOTE: Library LIB does not exist.
    2    libname lib "P:\dossier_calcul\26_06" ;
    NOTE: Library LIB does not exist.
    ERROR: Library LIB does not exist.
    ERROR: Import unsuccessful.  See SAS Log for details.
    3    libname lib "C:\Users\Bismilah_ salif\Desktop\stage";
    NOTE: Libref LIB was successfully assigned as follows:
          Engine:        V9
          Physical Name: C:\Users\Bismilah_ salif\Desktop\stage
     
    4    %macro test;
    5    OPTION mprint;
    6    %DO i=1 %TO 2 %BY 1;
    7    Data tati_&i;/* extraction de la 1ère ligne */
    8    set lib.toto (firstobs=&i obs=&i);
    9    run;
    10   Data tato_&i; /* ajout d'une variable age dans tati */
    11   set tati_&i;
    12   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    13   run;
    14   proc sql; /* pr select l'âge */
    15   select age INTO :age from tato_&i;
    16   quit;
    17
    18   data tato_&i;/* pour juste ajouter l'annee de naissance*/
    19   set tato_&i;
    20   annee=YEAR(Date_naiss_rentier);
    21   run;
    22   data tato_&i; /* pour changer le type de annee en carac :)*/
    23   set tato_&i;
    24   an=PUT(annee,$4.);
    25   run;
    26   data tato_&i; /* pour extraire les 3 derniers chiffres de l'année de naiss */
     
    27   set tato_&i;
    28   an_=SUBSTR(an,2);
    29   run;
    30   data tato_&i; /* concatenation */
    31   set tato_&i;
    32   ane=CATS('_',an_);
    33   run;
    34   /* data tato_&i;    pour changer le type de annee en numerique
    35    set tato_&i;                mais ça ne marche pas car on _919 comme valeur de ane
     
    36   ani=INPUT(ane,4.);
    37   run;*/
    38   proc sql; /*select du nbre de survivants à l'age 'age' c'est là le problème!! */
     
    39   select &ane INTO:l&i from lib.fem tato_&i where Age=&age;
    40   quit;
    41
    42   %put l&i=&l&i;
    43    %END;
    44    %mend test;
    45   %test;
    MPRINT(TEST):   Data tati_1;
    MPRINT(TEST):   set lib.toto (firstobs=1 obs=1);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_1 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.36 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   Data tato_1;
    MPRINT(TEST):   set tati_1;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.07 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_1;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.23 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.03 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.06 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   proc sql;
    22: LINE and COLUMN cannot be determined.
    NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN
                  where the error has occurred.
    ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
                  a numeric constant, a datetime constant, a missing value, INPUT, PUT, USER.
    WARNING: Apparent symbolic reference ANE not resolved.
    MPRINT(TEST):   select &ane INTO :l1 from lib.fem tato_1 where Age= 84;
    MPRINT(TEST):   quit;
    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.04 seconds
          cpu time            0.00 seconds
     
    WARNING: Apparent symbolic reference L not resolved.
    l1=&l1
     
     
    MPRINT(TEST):   Data tati_2;
    MPRINT(TEST):   set lib.toto (firstobs=2 obs=2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_2 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   Data tato_2;
    MPRINT(TEST):   set tati_2;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_2;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    22: LINE and COLUMN cannot be determined.
    NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN
                  where the error has occurred.
    ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
                  a numeric constant, a datetime constant, a missing value, INPUT, PUT, USER.
    WARNING: Apparent symbolic reference ANE not resolved.
    MPRINT(TEST):   select &ane INTO :l2 from lib.fem tato_2 where Age= 77;
    MPRINT(TEST):   quit;
    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
    WARNING: Apparent symbolic reference L not resolved.
    l2=&l2
     
    46   %macro test;
    47   OPTION mprint;
    48   %DO i=1 %TO 2 %BY 1;
    49   Data tati_&i;/* extraction de la 1ère ligne */
    50   set lib.toto (firstobs=&i obs=&i);
    51   run;
    52   Data tato_&i; /* ajout d'une variable age dans tati */
    53   set tati_&i;
    54   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    55   run;
    56   proc sql; /* pr select l'âge */
    57   select age INTO :age from tato_&i;
    58   quit;
    59
    60   data tato_&i;/* pour juste ajouter l'annee de naissance*/
    61   set tato_&i;
    62   annee=YEAR(Date_naiss_rentier);
    63   run;
    64   data tato_&i; /* pour changer le type de annee en carac :)*/
    65   set tato_&i;
    66   an=PUT(annee,$4.);
    67   run;
    68   data tato_&i; /* pour extraire les 3 derniers chiffres de l'année de naiss */
     
    69   set tato_&i;
    70   an_=SUBSTR(an,2);
    71   run;
    72   data tato_&i; /* concatenation */
    73   set tato_&i;
    74   ane=CATS('_',an_);
    75   run;
    76   /* data tato_&i;    pour changer le type de annee en numerique
    77    set tato_&i;                mais ça ne marche pas car on _919 comme valeur de ane
     
    78   ani=INPUT(ane,4.);
    79   run;*/
    80   proc sql; /*select du nbre de survivants à l'age 'age' c'est là le problème!! */
     
    81   select &ane INTO:l&i from lib.fem  where Age=&age;
    82   quit;
    83
    84   %put l&i=&l&i;
    85    %END;
    86    %mend test;
    87   %test;
    MPRINT(TEST):   OPTION mprint;
    MPRINT(TEST):   Data tati_1;
    MPRINT(TEST):   set lib.toto (firstobs=1 obs=1);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_1 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   Data tato_1;
    MPRINT(TEST):   set tati_1;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_1;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    22: LINE and COLUMN cannot be determined.
    NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN
                  where the error has occurred.
    ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
                  a numeric constant, a datetime constant, a missing value, INPUT, PUT, USER.
    WARNING: Apparent symbolic reference ANE not resolved.
    MPRINT(TEST):   select &ane INTO :l1 from lib.fem where Age= 84;
    MPRINT(TEST):   quit;
    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.01 seconds
     
    WARNING: Apparent symbolic reference L not resolved.
    l1=&l1
     
     
    MPRINT(TEST):   Data tati_2;
    MPRINT(TEST):   set lib.toto (firstobs=2 obs=2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_2 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   Data tato_2;
    MPRINT(TEST):   set tati_2;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_2;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    22: LINE and COLUMN cannot be determined.
    NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN
                  where the error has occurred.
    ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
                  a numeric constant, a datetime constant, a missing value, INPUT, PUT, USER.
    WARNING: Apparent symbolic reference ANE not resolved.
    MPRINT(TEST):   select &ane INTO :l2 from lib.fem where Age= 77;
    MPRINT(TEST):   quit;
    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
    WARNING: Apparent symbolic reference L not resolved.
    l2=&l2
     
    88   %macro test;
    89   OPTION mprint;
    90   %DO i=1 %TO 2 %BY 1;
    91   Data tati_&i;/* extraction de la 1ère ligne */
    92   set lib.toto (firstobs=&i obs=&i);
    93   run;
    94   Data tato_&i; /* ajout d'une variable age dans tati */
    95   set tati_&i;
    96   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    97   run;
    98   proc sql; /* pr select l'âge */
    99   select age INTO :age from tato_&i;
    100  quit;
    101
    102  data tato_&i;/* pour juste ajouter l'annee de naissance*/
    103  set tato_&i;
    104  annee=YEAR(Date_naiss_rentier);
    105  run;
    106  data tato_&i; /* pour changer le type de annee en carac :)*/
    107  set tato_&i;
    108  an=PUT(annee,$4.);
    109  run;
    110  data tato_&i; /* pour extraire les 3 derniers chiffres de l'année de naiss */
     
    111  set tato_&i;
    112  an_=SUBSTR(an,2);
    113  run;
    114  data tato_&i; /* concatenation */
    115  set tato_&i;
    116  ane=CATS('_',an_);
    117  run;
    118  /* data tato_&i;    pour changer le type de annee en numerique
    119   set tato_&i;                mais ça ne marche pas car on _919 comme valeur de ane
     
    120  ani=INPUT(ane,4.);
    121  run;*/
    122  proc sql; /*select du nbre de survivants à l'age 'age' c'est là le problème!! */
     
    123  select &ane INTO:l&i from lib.fem tato_&i where Age=&age;
    124  quit;
    125
    126  %put l&i=&l&i;
    127   %END;
    128   %mend test;
    129  %test;
    MPRINT(TEST):   OPTION mprint;
    MPRINT(TEST):   Data tati_1;
    MPRINT(TEST):   set lib.toto (firstobs=1 obs=1);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_1 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   Data tato_1;
    MPRINT(TEST):   set tati_1;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_1;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    22: LINE and COLUMN cannot be determined.
    NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN
                  where the error has occurred.
    ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
                  a numeric constant, a datetime constant, a missing value, INPUT, PUT, USER.
    WARNING: Apparent symbolic reference ANE not resolved.
    MPRINT(TEST):   select &ane INTO :l1 from lib.fem tato_1 where Age= 84;
    MPRINT(TEST):   quit;
    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
    WARNING: Apparent symbolic reference L not resolved.
    l1=&l1
     
     
    MPRINT(TEST):   Data tati_2;
    MPRINT(TEST):   set lib.toto (firstobs=2 obs=2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_2 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.00 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   Data tato_2;
    MPRINT(TEST):   set tati_2;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_2;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    22: LINE and COLUMN cannot be determined.
    NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN
                  where the error has occurred.
    ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
                  a numeric constant, a datetime constant, a missing value, INPUT, PUT, USER.
    WARNING: Apparent symbolic reference ANE not resolved.
    MPRINT(TEST):   select &ane INTO :l2 from lib.fem tato_2 where Age= 77;
    MPRINT(TEST):   quit;
    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
    WARNING: Apparent symbolic reference L not resolved.
    l2=&l2

  8. #8
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut
    Datametric : Pourquoi y a t il un blanc entre lib.fem et tato_&i dans ton FROM ?
    Je ne savais pas qu'il fallait mettre une virgule entre les tables...mais j'ai mis une virgule et exécuter, il ne donne toujours pas la valeur des l&i ...

  9. #9
    Rédacteur

    Homme Profil pro
    SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Inscrit en
    Avril 2009
    Messages
    2 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2009
    Messages : 2 497
    Points : 6 064
    Points
    6 064
    Par défaut
    ce que je ne comprends pas c'est comment est défini &ane. Je ne trouve pas sa définition.
    Ce qui donne : WARNING: Apparent symbolic reference ANE NOT resolved.

    Où est-ce ?

    La virgule dans le FROM permet de faire un INNER JOIN mais il faut (vaut mieux) une clause WHERE pour définir la clef de jointure.

  10. #10
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut
    ane est une variable qui vaut _926 pour la table tato_2 par exemple. Je l'ai defini pour pouvoir extraire le nombre de personnes de _926 à l'age Age dans la table fem.

  11. #11
    Rédacteur

    Homme Profil pro
    SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Inscrit en
    Avril 2009
    Messages
    2 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2009
    Messages : 2 497
    Points : 6 064
    Points
    6 064
    Par défaut
    peux-tu rajouter un affichage de &ane après cela et avant la proc SQL qui le rappelle ?

    Je pense qu'il n'y a rien et je ne vois toujours pas où cette macro-variable est définie dans ton code. Je vois &age par contre.

    A l'avenir, pour notre santé mentale à tous, ajoute donc une table exemple qui nous permette d'exécuter ton code. Ca pourrait nous aider.

  12. #12
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut
    il ne reconnait pas &ane...voici ce qu'il affiche dans le log:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    2    %macro test;
    3    OPTION mprint;
    4    %DO i=1 %TO 2 %BY 1;
    5    Data tati_&i;/* extraction de la 1ère ligne */
    6    set lib.toto (firstobs=&i obs=&i);
    7    run;
    8    Data tato_&i; /* ajout d'une variable age dans tati */
    9    set tati_&i;
    10   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    11   run;
    12   proc sql; /* pr select l'âge */
    13   select age INTO :age from tato_&i;
    14   quit;
    15
    16   data tato_&i;/* pour juste ajouter l'annee de naissance*/
    17   set tato_&i;
    18   annee=YEAR(Date_naiss_rentier);
    19   run;
    20   data tato_&i; /* pour changer le type de annee en carac :)*/
    21   set tato_&i;
    22   an=PUT(annee,$4.);
    23   run;
    24   data tato_&i; /* pour extraire les 3 derniers chiffres de l'année de naiss */
     
    25   set tato_&i;
    26   an_=SUBSTR(an,2);
    27   run;
    28   data tato_&i; /* concatenation */
    29   set tato_&i;
    30   ane=CATS('_',an_);
    31   run;
    32   %put ane=&ane;
    33   /* data tato_&i;    pour changer le type de annee en numerique
    34    set tato_&i;                mais ça ne marche pas car on _919 comme valeur de ane
     
    35   ani=INPUT(ane,4.);
    36   run;
    37   proc sql; select du nbre de survivants à l'age 'age' c'est là le problème!!
     
    38   select &ane INTO:l&i from lib.fem,tato_&i where Age=&age;
    39   quit;
    40
    41   %put l&i=&l&i;*/
    42    %END;
    43    %mend test;
    44   %test;
    MPRINT(TEST):   Data tati_1;
    MPRINT(TEST):   set lib.toto (firstobs=1 obs=1);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_1 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.34 seconds
          cpu time            0.03 seconds
     
     
    MPRINT(TEST):   Data tato_1;
    MPRINT(TEST):   set tati_1;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.06 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_1;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.50 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.03 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_1;
    MPRINT(TEST):   set tato_1;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_1.
    NOTE: The data set WORK.TATO_1 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.08 seconds
          cpu time            0.01 seconds
     
     
    WARNING: Apparent symbolic reference ANE not resolved.
    ane=&ane
    MPRINT(TEST):   Data tati_2;
    MPRINT(TEST):   set lib.toto (firstobs=2 obs=2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set LIB.TOTO.
    NOTE: The data set WORK.TATI_2 has 1 observations and 19 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   Data tato_2;
    MPRINT(TEST):   set tati_2;
    MPRINT(TEST):   age=YEAR(TODAY())-YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATI_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 20 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   proc sql;
    MPRINT(TEST):   select age INTO :age from tato_2;
    MPRINT(TEST):   quit;
    NOTE: PROCEDURE SQL used (Total process time):
          real time           0.00 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   annee=YEAR(Date_naiss_rentier);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 21 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.00 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an=PUT(annee,$4.);
    WARNING: Variable annee has already been defined as numeric.
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 22 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   an_=SUBSTR(an,2);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 23 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    MPRINT(TEST):   data tato_2;
    MPRINT(TEST):   set tato_2;
    MPRINT(TEST):   ane=CATS('_',an_);
    MPRINT(TEST):   run;
     
    NOTE: There were 1 observations read from the data set WORK.TATO_2.
    NOTE: The data set WORK.TATO_2 has 1 observations and 24 variables.
    NOTE: DATA statement used (Total process time):
          real time           0.01 seconds
          cpu time            0.01 seconds
     
     
    WARNING: Apparent symbolic reference ANE not resolved.
    ane=&ane
    Je vais joindre une table toto sur laquelle on peut exécuter le code...mais il faudra la mettre dans une bibliothèque de nom lib.Je joins aussi les 2 tables tato_1 et tato_2 après l'exécution. ça me casse vraiment la tète..Je me demande bien si c'est possible...je vous remercie
    Fichiers attachés Fichiers attachés

  13. #13
    Membre actif
    Femme Profil pro
    Analyste en Intelligence d'Affaires (BI)
    Inscrit en
    Avril 2008
    Messages
    245
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Analyste en Intelligence d'Affaires (BI)
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2008
    Messages : 245
    Points : 290
    Points
    290
    Par défaut
    Bonjour Kalandèn,

    Ce que Datametric essaye de t'expliquer c'est que:
    Pour faciliter l'aide il faudrait des exemples concrets : comme pour telle variable et telle opération je souhaiterais tel résultat.
    Il y avait un début d'exemple avec cette citation.
    (au fait je veux selectionner le nombre de survivants ds la table fem à partir de l'année ( annee ds la table tato_&i que j'ai transformé en ane = _926) car dans la table fem les années sont definies comme suit :_900 _901 ...jusquà _005 (j'ai joint la table ci-dessus).
    Pour revenir au programme :

    Un petit remaniement de la proc sql s'impose.
    Car il me semble que ta proc sql ne fait pas ce que ton commentaire prétend.
    Si j'ai bien compris tu voudrais avoir:

    Pour i=1 : le nombre de survivants de la table fem avec les critères suivants :

    Lorsque âge de la table tato_1 vaut l'âge de la table fem (ici 93 ans).
    et recherche de la valeur de ane (_919) de la table tato_1 dans la liste des variables de la table fem (_....).
    Donc dans la table fem le croisement 93 ans /_919 vaut : 38959.

    Problème 1:

    &ane n'est pas reconnu car elle n'a jamais été définie comme une macro variable, voir étape concaténation.

    Problème 2:

    Comme ta proc sql fait appel à deux tables avec des noms de variables identiques (âge) autant (je sais plus comment ca s'appelle)...indicé tes tables avec des as quelque chose:
    Exemple de remaniment mais ne répond pas encore au besoin.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    
    proc sql; 
    SELECT t.ane INTO:l&i 
    FROM fem as f, tato_&i as t
    WHERE f.Age=t.age; 
    quit;
    Problème 3 À résoudre :

    Partir de la valeur d'une variable d'une table (tato_1) pour rechercher une variable dans une autre table (fem) sous condition d'égalité de valeur d'une variable clé (âge).

    To be continued

  14. #14
    Membre actif
    Femme Profil pro
    Analyste en Intelligence d'Affaires (BI)
    Inscrit en
    Avril 2008
    Messages
    245
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Analyste en Intelligence d'Affaires (BI)
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2008
    Messages : 245
    Points : 290
    Points
    290
    Par défaut Solution possible
    Voici un code qui au moins sélectionne à la fin le nombre de survivants pour un âge donnée.

    PS: je me suis permise de regrouper les data avec les opérations de création de variable sur la même table tato_&i (cela n'engage que moi évidemment)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    %macro test;
    OPTION SPOOL;
    %DO i=1 %TO 2 %BY 1;
    
    DATA tati_&i;/*extraction de la 1ère ligne */
    SET toto (firstobs=&i obs=&i);
    run;
    
    DATA tato_&i; 
    SET tati_&i;
    age=YEAR(TODAY())-YEAR(Date_naiss_rentier);/* ajout d'une variable age dans tati */
    run;
    
    proc sql; /* pr select l'âge */
    SELECT age INTO :age FROM tato_&i;
    quit;
    
    
    DATA tato_&i; 
    SET tato_&i;
    
    /* pour juste ajouter l'annee de naissance*/
    annee=YEAR(Date_naiss_rentier);
    /* pour changer le type de annee en carac :)*/
    an=PUT(annee,$4.);
    /* pour extraire les 3 derniers chiffres de l'année de naiss */
    an_=SUBSTR(an,2);
    /* concatenation */
    ane=CATS('_',an_);
    /* pour changer le type de annee  en numerique mais ça ne marche pas
     car on a  _919  comme valeur de ane.*/
    /*ani=INPUT(ane,4.);*/
    run;
    
    /*RAJOUT de cette étape*/
    
    proc sql; /* pr select l'année */
    SELECT ane INTO :val_ane FROM tato_&i;
    quit;
    
    /* select du nbre de survivants à l'age &age*/
    proc sql; 
    
    SELECT &val_ane INTO:l&i
    FROM fem as f, tato_&i as t
    WHERE f.Age=t.age; 
    quit;
    
    %put l&i=&&l&i;
    %END;
    %mend test;
     options mprint;
    %test;
    Voilà.

  15. #15
    Rédacteur

    Homme Profil pro
    SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Inscrit en
    Avril 2009
    Messages
    2 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : SAS ALLIANCE SILVER. Consultant et formateur SAS et Cognos.
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2009
    Messages : 2 497
    Points : 6 064
    Points
    6 064
    Par défaut


    La définition de ane ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    DATA tato_&i; /* concatenation */
    SET tato_&i;
    ane=CATS('_',an_);
     run;
    %put ane=&ane;
    n'est pas correcte puisque ane n'est pas enregistrée dans une macro-variable.
    Il faudrait :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    DATA tato_&i; /* concatenation */
    SET tato_&i;
    CALL SYMPUTX (ane , CATS('_',an_));
     run;
    %put ane=&ane;

  16. #16
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2012
    Messages : 39
    Points : 21
    Points
    21
    Par défaut
    Exactement ça marche très bien maintenant avec vos differentes remarques...ce que MDsas a dit, c'est ce que j voulais faire( selection ds une table à partir d'une selection d'une autre table)...et je n'avais pas defini ane ds une macro variable...le CALL SYMPUT de Datametric aussi marche très bien.je ne sais vraiment pas comment vs remercier..

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [SQL] "Différent de" dans une PROC SQL
    Par logiclogic dans le forum SAS Base
    Réponses: 5
    Dernier message: 19/04/2013, 09h33
  2. Réponses: 2
    Dernier message: 02/07/2012, 17h03
  3. Réponses: 17
    Dernier message: 09/03/2011, 11h14
  4. Definir un format décimal dans une proc SQL
    Par pierre24 dans le forum SAS Base
    Réponses: 1
    Dernier message: 07/08/2008, 09h36
  5. Faire un simple SELECT dans une Proc. Stock
    Par MaelstroeM dans le forum Oracle
    Réponses: 2
    Dernier message: 29/08/2007, 09h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo