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

ODS et reporting Discussion :

DATA _NULL_ split avec espace après retour à la ligne


Sujet :

ODS et reporting

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 7
    Points : 6
    Points
    6
    Par défaut DATA _NULL_ split avec espace après retour à la ligne
    Bonjour,

    je veux transférer le contenu d'un champ vers un fichier texte,
    ce champ est une longue variable caractère de longueur $2000 du type :
    (year=2001 and month=01 and day=01) or (year=2001 and month=01 and day=02) ...... jusqu'a 31 fois pour les mois de 31 jours,

    quand je cree un fichier txt à partir de ce champ, les lignes sont limités à 262, et donc les retours à la ligne sont fait un peu n'importe comment: au milieu d'un YEAR ou un OR et donc je me retrouve avec un YE AR ou O R (j'ai pas essayé avec un lrecl mais ça pas ça le problème: je veux pas me retrouver avec des lignes très allongées),

    qu'est ce qu'on peut me conseiller pour avoir un retour intelligent à la ligne, si ça se peut se faire sous une proc je prends aussi

    Merci d'avance

    un petit code pour comprendre: dans mon cas retour à la ligne en milieu d'un MONTH

    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 test;
    do i=1 to 31;
    var="(year=2001 and month=01 and day="!!compress(i)!!")";
    output;
    end;
     
    proc sql;
    select var into :groupe  separated by ' or ' from test;
    quit;
     
    data test1;
    char="&groupe";
    run;
     
    data _null_;
    file <chemin> /*lrecl=3000*/;
    set test1;
    put char;
    run;

  2. #2
    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
    J'ai un souci avec ton problème, c'est que quand je le teste chez moi, je n'ai pas de problème !

    D'une part, la log indique bien que tout est exporté sur une seule ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    NOTE: The file "c:\temp\test.txt" is:
          File Name=c:\temp\test.txt,
          RECFM=V,LRECL=3000
     
    NOTE: 1 record was written to the file "c:\temp\test.txt".
          The minimum record length was 1196.
          The maximum record length was 1196.
    NOTE: There were 1 observations read from the data set WORK.TEST1.
    --> As tu le même type de résultat dans la log ?

    D'autre part, quand j'ouvre le fichier, tout est bien sur une ligne.
    Le problème vient peut être de l'application avec laquelle tu ouvres le fichier txt ?
    Moi je l'ouvre avec le "bloc note" de Windows
    --> Avec quelle application ouvres tu ton fichier txt ?

  3. #3
    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
    Voilà quand même une piste de solution

    Cela consiste à redécomposer char en 31 variables char_1 à char_31,
    et à les exporter l'une après l'autre.

    Pour cela, on part du principe que la variable char a une structure vraiment figée : les longueurs des champs sont toujours les mêmes. Avec le fait que la longueur augmente de +1 quand l'on passe du 9ième au 10ième jour.

    L'étape data est sûrement optimisable, j'ai rajouté une ou deux rustines pour gérer des anos (notamment loop=32)
    J'ai aussi géré le cas des mois de moins de 31 jours.
    POur le test, j'ai fait un putlog pour visualiser les résultats dans la log : il te suffit normalement de remettre le put classique et le file.

    Le code :
    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 _null_ ;
        set test1 ;  
        array char_n{31} $39  char_1-char_31 ;
     
            char_n(1) = substr (char, 1, 35) ;
     
        do loop = 2 to 9 ;
            char_n(loop) = substr (char, 35     + (loop-2) * 38 , 38) ;
            end; 
     
        do loop = 10 to 31 ;
            if 28 + (loop-2) * 39 < length(char) 
            then 
            char_n(loop) = substr (char, min (28 + (loop-2) * 39, length(char)-38) , 39) ;
            end; 
     
        do loop = 1 to 31 ;
            if not missing(char_n(loop)) then putlog char_n(loop) ;
        end ; 
    run ;
    Le résultat obtenu dans la 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
    (year=2001 and month=01 and day=1)
    or (year=2001 and month=01 and day=2)
    or (year=2001 and month=01 and day=3)
    or (year=2001 and month=01 and day=4)
    or (year=2001 and month=01 and day=5)
    or (year=2001 and month=01 and day=6)
    or (year=2001 and month=01 and day=7)
    or (year=2001 and month=01 and day=8)
    or (year=2001 and month=01 and day=9)
    or (year=2001 and month=01 and day=10)
    or (year=2001 and month=01 and day=11)
    or (year=2001 and month=01 and day=12)
    or (year=2001 and month=01 and day=13)
    or (year=2001 and month=01 and day=14)
    or (year=2001 and month=01 and day=15)
    or (year=2001 and month=01 and day=16)
    or (year=2001 and month=01 and day=17)
    or (year=2001 and month=01 and day=18)
    or (year=2001 and month=01 and day=19)
    or (year=2001 and month=01 and day=20)
    or (year=2001 and month=01 and day=21)
    or (year=2001 and month=01 and day=22)
    or (year=2001 and month=01 and day=23)
    or (year=2001 and month=01 and day=24)
    or (year=2001 and month=01 and day=25)
    or (year=2001 and month=01 and day=26)
    or (year=2001 and month=01 and day=27)
    or (year=2001 and month=01 and day=28)
    or (year=2001 and month=01 and day=29)
    or (year=2001 and month=01 and day=30)
    or (year=2001 and month=01 and day=31)

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 7
    Points : 6
    Points
    6
    Par défaut
    j'ai exactement le même message sur la log, y'a donc un lien avec l'application avec laquelle j'ouvre le fichier:

    bloc notes de windows (vista) => affichage sur 2 ligne avec un mot splitté et un espace introduit avec le retour à la ligne.
    notepad++ et similaires : affichage sur 1 ligne.
    wordpad : des lignes raccourcies ( 70/74 caracteres) ! donc plusieurs lignes et une bonne gestion des retours à la ligne ( pas de split ...).

    merci pour le code, on évite ce problème de lignes allongées et c'est plus présentable.

Discussions similaires

  1. [CR XI] If [Espace] then [Retour à la ligne]?
    Par Cersei dans le forum Formules
    Réponses: 3
    Dernier message: 08/05/2013, 14h56
  2. Réponses: 3
    Dernier message: 11/04/2011, 16h51
  3. [DOM] Parser un fichier xml (sans espaces et retours à la ligne)
    Par rizki1 dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 04/05/2010, 10h26
  4. [POO] unset($data->ma variable avec espace)
    Par PrOkIuM dans le forum Langage
    Réponses: 1
    Dernier message: 04/02/2009, 15h54
  5. [XSLT][MSXML4] Conserver espaces et retour à la ligne
    Par arthix dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 22/01/2007, 10h27

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