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 :

Récuperer la valeur d'une colonne dans une autre colonne


Sujet :

SAS Base

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2011
    Messages
    155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2011
    Messages : 155
    Points : 37
    Points
    37
    Par défaut Récuperer la valeur d'une colonne dans une autre colonne
    Bonjour,

    j'ai une table avec 2 colonnes elle contient 3 lignes.exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Col1  Col2 
    A A   BB
    A A   DD
    A A   JJ
    je veux récupèrer la valeur A A dans la colonne COL2 pour avoir ce résulat on gardant les deux colonnes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Col1  Col2 
    A A   BB
    A A   DD
    A A   JJ
    A A   A A
    Y a til une solution svp ?

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    747
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 747
    Points : 978
    Points
    978
    Par défaut
    Il faut expliquer la logique de garder "A A" car là perso je ne vois pas...

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2011
    Messages
    155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2011
    Messages : 155
    Points : 37
    Points
    37
    Par défaut RECUPERER LA VALEUR DE LA COLONNE DANS UNE AUTRE COLONNE
    Dsl !!
    je vais ssayer d'expliquer en détaille:
    j'ai une table "matable" avec 5 colonne alpha

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    col1   Col2      Col3     Col4     Col5     Col6
     id1    toto      tobo     tomo    toko    toyo
     id1    toto      bomo    tomo    toko    toyo
     id1    toto      soso     tomo    toko    toyo
     id2    titi        tati      tabi      tani     babi
     id2    titi        tayi      tabi      tani     babi
    Je veux créer une table résultat depuis "matable" sachant qu'il faut garder toutes les colonnes et créer une nouvelle ligne en plus pour chaque "id"qui contient la valeur de la colonne COL2 pour l'ID dans la col3 pour avoir ce résultat:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    col1   Col2      Col3       Col4      Col5     Col6
     id1    toto      toto      tomo    toko    toyo
     id1    toto      tobo      tomo    toko    toyo
     id1    toto      bomo     tomo    toko    toyo
     id1    toto      soso      tomo    toko    toyo
     id2    titi        titi        tabi      tani     babi
     id2    titi        tati       tabi      tani     babi
     id2    titi        tayi       tabi      tani     babi
    Pour info dans chaque colonne il y a les même valeurs groupé avec l'ID sauf pour la COL2 là ou il y a différent valeur pour le même ID.

    Merci pour votre aide

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2011
    Messages
    155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2011
    Messages : 155
    Points : 37
    Points
    37
    Par défaut
    oups ma table contient 6 colonnes .

    aussi une précision:il y avait une erreur dans le mail précedent je veux dire :

    Pour info dans chaque colonne il y a les même valeurs groupé avec l'ID sauf pour la COL3 et non pas la COL2

  5. #5
    Membre éprouvé
    Avatar de m.brahim
    Homme Profil pro
    SAS / BIG DATA
    Inscrit en
    Juillet 2011
    Messages
    461
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : SAS / BIG DATA
    Secteur : Conseil

    Informations forums :
    Inscription : Juillet 2011
    Messages : 461
    Points : 1 119
    Points
    1 119
    Billets dans le blog
    14
    Par défaut
    Bonjour,

    Je te propose cette solution:
    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
     
    data test; 
    input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $;
    cards;
     
     id1    toto      tobo     tomo    toko    toyo
     id1    toto      bomo    tomo    toko    toyo
     id1    toto      soso     tomo    toko    toyo
     id2    titi        tati      tabi      tani     babi
     id2    titi        tayi      tabi      tani     babi 
    ;
    run;
     
    proc sort data=test; by col2; run;
     
    data test1 ;
    set test;
    by col2;
    if last.col2 then output;
    run;
     
    data _null_;
    set test1 end=last;
    call symputx ('col1'||left(_n_),left(col1));
    call symputx ('col2'||left(_n_),left(col2));
    call symputx ('col3'||left(_n_),left(col2));
    call symputx ('col4'||left(_n_),left(col4));
    call symputx ('col5'||left(_n_),left(col5));
    call symputx ('col6'||left(_n_),left(col6));
    call symput ('nbr',_n_);
    run;
    %put &nbr;
     
     
    DATA tables (drop=i);
    do i=1 to &nbr;
    col1=symget(cats('col1',i));	
    col2=symget(cats('col2',i));
    col3=symget(cats('col3',i));
    col4=symget(cats('col4',i));
    col5=symget(cats('col5',i));
    col6=symget(cats('col6',i));
    output;
    end;
    run ; 
     
    data fin;
    set test tables;
    run;
     
    proc sort data =fin;by col2; run;
    Cordialement
    Certification des Talents de la programmation In Memory Statistics sur HADOOP:
    http://talents-imstat.groupe-avisia....avance?uid=162

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2011
    Messages
    155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2011
    Messages : 155
    Points : 37
    Points
    37
    Par défaut
    Merci brahim mais ça donne pas ce que je veux

  7. #7
    Membre éclairé
    Homme Profil pro
    responsable adjoint service stat
    Inscrit en
    Mars 2009
    Messages
    448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France

    Informations professionnelles :
    Activité : responsable adjoint service stat
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2009
    Messages : 448
    Points : 823
    Points
    823
    Par défaut
    Je me lance, même si honnêtement je suis pas sûr d'avoir tout à fait compris l'énnoncé...
    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
    DATA test; 
    input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $;
    cards;
     id1    toto      tobo     tomo    toko    toyo
     id1    toto      bomo    tomo    toko    toyo
     id1    toto      soso     tomo    toko    toyo
     id2    titi        tati      tabi      tani     babi
     id2    titi        tayi      tabi      tani     babi 
    ;
    run ; 
     
    proc sort data = test ; 
        by col1 ;
    run ; 
     
    data test2 ;
        set test ;
        by col1 ;
        output ; 
        if last.col1 then do ;
            col3 = col2 ;
            output ;
            end ;
    run ;

  8. #8
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2011
    Messages
    155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2011
    Messages : 155
    Points : 37
    Points
    37
    Par défaut
    Merci Remi !! tu as tout compris
    ton code donne exactement ce que je veux .
    Merci à toi

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

Discussions similaires

  1. [XL-2007] Récupérer valeurs d'une colonne vers une liste déroulante sur autre colonne d'une nouvelle feuille
    Par redhotchilipeppers dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 07/07/2014, 17h26
  2. rechercher dans une ligne et copier la colonne dans un autre document
    Par myayo001 dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 21/03/2014, 13h11
  3. Réponses: 7
    Dernier message: 25/03/2011, 10h52
  4. [POO] dans une classe, appeler une fonction dans une méthode
    Par arnaudperfect dans le forum Langage
    Réponses: 3
    Dernier message: 26/08/2007, 23h04
  5. Envoyer une formulaire dans une page dans une Frame
    Par zooffy dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 29/06/2007, 10h13

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