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

Débutez Discussion :

Création de variable avec array et valeurs manquantes


Sujet :

Débutez

  1. #1
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 18
    Points : 22
    Points
    22
    Par défaut Création de variable avec array et valeurs manquantes
    Bonjour à tous,
    Je cherche à savoir la nature des enfants d’une femme, c’est-à-dire je veux savoir si elle a eu ses enfants avec le partenaire actuel ou celui précèdent (ou les deux).

    L’idée est de construire une variable STATENF à deux modalités :
    STATENF = 'cjt_pre' /*si la naissance a eu lieu au cours de la première relation */
    STATENF = ‘ctj_act’ /*si la naissance a eu lieu au cours de la deuxième relation */

    Dans ma base j’ai les éléments suivants :

    IDMEN= identifiant ménage ;
    COH1 = année de la première cohabitation qui s’est terminé par le mariage ;
    MAR1 = année du mariage (qui a suivi COH1) ;
    SEP1 = année de séparation (de facto) ;
    DIV1 = année du divorce ;
    COH2 = année de la deuxième cohabitation qui s’est terminé par le mariage (MAR2) ;
    MAT2 = année du deuxième mariage (qui a suivi COH2) ;

    Je cherche donc à savoir si les enfants sont nés dans une relation qui est tjs en cours ou si les enfants sont nés dans la relation précédente.

    IDMEN COH1 MAT1 SEP1 DIV1 COH2 MAT2 ENF1 ENF2 ENF3
    001 1980 1982 . 1990 . 1999 1985 2000 2001
    002 . 1950 1960 1962 1970 . 1951 1953 1958 .
    003 . 1990 1999 2001 1999 2005 1992 2000 .


    Dans mon exemple pour l’IDMEN '001' l’ENF1 est né dans la relation précédente (STATENF = 'cjt_pre'), tandis que ENF2 et ENF3 sont nés dans la relation actuelle (STATENF = ‘ctj_act’) ;
    Il y aura donc trois variables STATENF (STATENF1- STATENF3) pour les trois enfants de la base. J’ai essayé avec ce code, mais j’ai l’impression que les array n’aiment pas lorsqu’il y a une valeur manquante (ex IDMEN '001' pour SEP1 = . ‘la femme a divorcé du mari sans avoir vecu une période de séparation de facto).
    data histcj3 ; set histcj2;

    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
     
    data histcj3 ; set histcj2; 
    array mar (2) COH1 MAR1 ; 
    array sep (4) SEP1 DIV1 COH2 MAR2 ;
    do i=1 to 2; 
     do j=1 to 4; 
     	if enf1 ne . and anenf1>= mar(i)  and enf1<sep(j) then statenf1='cjt_pre'; 
    	if enf1 ne . and anenf1>= mar(i) and enf1>=sep(j) then statenf1='ctj_act' ; 
     
    if enf2 ne . and enf2>= mar(i)  and enf2<sep(j) then statenf2='cjt_pre'; 
    	if enf2 ne . and enf2>= mar(i) and enf2>=sep(j) then statenf2='ctj_act' ;
     
    	if enf3 ne . and enf3>= mar(i)  and enf3<sep(j) then statenf3='cjt_pre'; 
    	if enf3 ne . and enf3>= mar(i) and enf3>=sep(j) then statenf3='ctj_act' ;
     
     
    end ; 
    	end; 
     
    run;
    Pour que l’enfant soit né dans une relation précédente, il doit être né avant la séparation ou le divorce et avant la deuxième cohabitation ou le deuxième mariage ;
    A contrario, un enfant est né dans la relation actuelle lorsqu’il est né après (ou au même temps que la nouvelle cohabitation ou le nouveau mariage = > ex IDMEN ‘0003’ la SEP1 a lieu au même temps que COH2).

    Pour info, tous les individus de cette base ont mis à terme la première relation (MAR1).
    Savez-vous comment je peux corriger mon bout de programme ?

    Merci beaucoup pour votre aide !

  2. #2
    Membre expérimenté
    Homme Profil pro
    Développeur en SAS/ Statisticien
    Inscrit en
    Janvier 2013
    Messages
    483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur en SAS/ Statisticien
    Secteur : Enseignement

    Informations forums :
    Inscription : Janvier 2013
    Messages : 483
    Points : 1 552
    Points
    1 552
    Par défaut
    Bonjour,
    J'ai fait quelques modifications, voici ton code dans sa nouvelle version.
    Est ce cela répond bien à ta question ?
    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
     
    Data histcj_1 ;
    INFILE cards dlm=' ' dsd missover  ; 
    input IDMEN COH1 MAR1 SEP1 DIV1 COH2 MAR2 ENF1 ENF2 ENF3 ;
    cards;
    001 1980 1982 . 1990 . 1999 1985 2000 2001
    002 . 1950 1960 1962 1970 . 1951 1953 1958 .
    003 . 1990 1999 2001 1999 2005 1992 2000 . 
    ; run ; 
     
    data histcj_2 ;
    set  histcj_1 ; 
    array  histcj(*)  COH1 MAR1 SEP1 DIV1 COH2 MAR2 ;
    array     enf(*)  ENF1-ENF3 ;
    array statenf(*)$ STATENF1-STATENF3 ;
     
    do i=1 to dim(histcj) ;	 
    if not missing(histcj(i)) then do ; 
     
    TEMP1=max(of COH1 MAR1) ;
    TEMP2=min(of SEP1 DIV1 COH2 MAR2) ;
     
    do j=1 to dim(enf) ; 
    if not missing(enf(j)) then statenf(j)=IFC(TEMP1<= enf(j) <TEMP2, 'cjt_pre', 'ctj_act') ;
    end ;	
                                  end ;
    end ; 
    Drop i j temp: ; 
    run;
    Cordialement
    Ward

  3. #3
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 18
    Points : 22
    Points
    22
    Par défaut
    Bonjour Ward,

    En effet je me suis aperçue que mon code avait pas mal de erreurs ...

    Donc j'ai corrigé comme ça :

    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
     
     
    data histcj3 ; set histcj2; 
     
    length statenf1 $7. statenf2 $7. statenf3 $7. statenf4 $7. statenf5 $7. statenf6 $7. statenf7 $7.;
    array mar (2) COHA_PRE1 mar1 ; 
    array vars (*) SEPFAT1 SEPLEG1 DIVORCE1 COHA_PRE2 MAR2 ;
    min=min(of vars(*));
     
                               statenf1='';   
    						      statenf2='';
    							     statenf3='';
    								    statenf4='';
    									   statenf5='';
    									      statenf6='';
    										     statenf7='';
     
                               do n=1 to 2;
     
                               if ANENF1 ne . and ANENF1>=mar(n) and ANENF1<=min then statenf1='cjt_pre';
                               if statenf1='' and ANENF1>0 then statenf1='ctj_act'; 
     
    						   if ANENF2 ne . and ANENF2>=mar(n) and ANENF2<=min then statenf2='cjt_pre';
                               if statenf2='' and ANENF2>0 then statenf2='ctj_act'; 
     
    						   if ANENF3 ne . and ANENF3>=mar(n) and ANENF3<=min then statenf3='cjt_pre';
                               if statenf3='' and ANENF3>0 then statenf3='ctj_act'; 
     
    						   if ANENF4 ne . and ANENF4>=mar(n) and ANENF4<=min then statenf4='cjt_pre';
                               if statenf4='' and ANENF4>0 then statenf4='ctj_act'; 
     
    						   if ANENF5 ne . and ANENF5>=mar(n) and ANENF5<=min then statenf5='cjt_pre';
                               if statenf5='' and ANENF5>0 then statenf5='ctj_act'; 
     
    						   if ANENF6 ne . and ANENF6>=mar(n) and ANENF6<=min then statenf6='cjt_pre';
                               if statenf6='' and ANENF6>0 then statenf6='ctj_act'; 
     
    						   if ANENF7 ne . and ANENF7>=mar(n) and ANENF7<=min then statenf7='cjt_pre';
                               if statenf7='' and ANENF7>0 then statenf7='ctj_act'; 
     
    drop n i; end; 
     
    array statenf (*) $ statenf1-statenf7 ;
    nbcjtpre=0; 
    do i=1 to dim(statenf) ; 
    if statenf(i) ne '' and statenf(i)='cjt_pre' then nbcjtpre=nbcjtpre+1 ; end; 
     
    run;
    Mon code est beaucoup moins propre que le tien mais je pense avoir réussi à faire ce que je voulais.
    Le tien pourra m'aider lorsque je tentera de faire des 'array' plus complexes

    Merci encore

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

Discussions similaires

  1. Création de variables avec d'autres valeurs
    Par chow59 dans le forum Débutez
    Réponses: 3
    Dernier message: 19/09/2013, 10h43
  2. Création de variables : condition IF et valeurs manquantes
    Par craow87000 dans le forum SAS Base
    Réponses: 10
    Dernier message: 22/11/2011, 15h23
  3. Création de variable avec un pipe
    Par mouatte dans le forum Linux
    Réponses: 3
    Dernier message: 14/02/2009, 08h06
  4. Création de variable avec un type variable !
    Par Marcool dans le forum C++
    Réponses: 17
    Dernier message: 28/08/2008, 16h22
  5. création de tableaux avec Array() et élément 'fantome'
    Par Talieth dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 22/11/2005, 09h49

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