DATA Step, Macro, Functions and more

PUT ZD and PD variables with readable characters

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

PUT ZD and PD variables with readable characters

Hi,

 

I have a Z/OS Sas code with two input files and in both files I have some ZD and PD variables

 

@118        E5FS047_MONT_DROIT                               PD7.2
@119        E5FM222_MONT_DROIT_VENTIL               ZD13.2



PROC SQL;                                                 
   CREATE TABLE CLIC_PROF AS                              
   SELECT                                                 
         E5FS047_ID_CLINT_USAG,                           
         E5FS047_TYP_SDU,                                 
         E5FS047_SEQ_SDU,                                 
         E5FS047_PER_AN,                                  
         E5FS047_PER_MOIS,                                
         E5FS047_ID_INSTRC_VENTIL_5,                      
         E5FS047_TYP_ITEM_RESUL_E5,                       
         E5FS047_MONT_DROIT,                              
         E5FS047_MONT_PEINE,                              
         E5FS047_MONT_INTE_COTIS,                         
         E5FS047_MONT_INTE_DEPEN,                         
         E5FS047_MONT_INTE_CYCL,                          
         E5FS047_MONT_AUTR,                               
         E5FM222_MONT_DROIT_VENTIL,                       
         E5FM222_MONT_DECL_E5                             
   FROM E2                                                
   INNER JOIN IV                                          
   ON   E2.E5FS047_ID_CLINT_USAG = IV.E5FM222_NO_USAG     
   AND  E2.E5FS047_TYP_SDU       = IV.E5FM222_TYP_SDU     
   AND  E2.E5FS047_SEQ_SDU       = IV.E5FM222_SEQ_SDU     
   AND  E2.E5FS047_PER_AN        = IV.E5FM222_PER_AN      
   AND  E2.E5FS047_PER_MOIS      = IV.E5FM222_PER_MOIS    
   AND  E2.E5FS047_ID_INSTRC_VENTIL_5 =                   
        IV.E5FM222_ID_INSTRC_VENTIL_5                     
   WHERE E5FS047_TYP_ITEM_RESUL_E5 = 'A'                  
   AND   E5FM222_MONT_DROIT_VENTIL < E5FM222_MONT_DECL_E5 
   ;                                                      
QUIT;                                                     

DATA _NULL_;                                   
SET CLIC_PROF;                                 
FILE SORTIE;                                                                          
PUT  @001 E5FS047_ID_CLINT_USAG        $CHAR10  
     @011 ';'                                   
     @012 E5FS047_TYP_SDU              $CHAR2   
     @014 ';'                                   
     @015 E5FS047_SEQ_SDU              $CHAR4   
     @019 ';'                                   
     @020 E5FS047_PER_AN               ZD4.0    
     @024 ';'                                   
     @025 E5FS047_PER_MOIS             ZD2.0    
     @027 ';'                                   
     @028 E5FS047_ID_INSTRC_VENTIL_5   ZD9.0    
     @038 ';'                                   
     @039 E5FS047_TYP_ITEM_RESUL_E5    $CHAR2   
     @041 ';'                                   
     @042 E5FS047_MONT_DROIT           PD7.2    
     @049 ';'                                   
     @050 E5FS047_MONT_PEINE           PD7.2    
     @058 ';'                                   
     @059 E5FS047_MONT_INTE_COTIS      PD7.2    
     @065 ';'                                   
     @066 E5FS047_MONT_INTE_DEPEN      PD7.2    
     @073 ';'                                   
     @074 E5FS047_MONT_INTE_CYCL       PD7.2    
     @080 ';'                                   
     @081 E5FS047_MONT_AUTR            PD7.2    
     @088 ';'                                   
     @089 E5FM222_MONT_DROIT_VENTIL    ZD13.2   
     @105 ';'                                   
     @106 E5FM222_MONT_DECL_E5         ZD13.2;  
RUN;                                            



 

 

The way I am doing it my output file looks like this:

1222238931;TQ;0001;201F;0B;04229918I ;A ;  ä ¸;  Êï)

 

So my question is, how can I do to convert my ZD and PD variables before PUT ?

 

Thank you,

Rodrigo


Accepted Solutions
Solution
‎11-18-2016 01:25 PM
Super User
Posts: 7,832

Re: PUT ZD and PD variables with readable characters

Use 16.2 instead of PD7.2.

With the ZDw, add 1 to the length for formats with no fractions, 2 for formats with fractions.

(ZD13.2 -> 15.2, ZD4.0 -> 5.0)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
PROC Star
Posts: 1,760

Re: PUT ZD and PD variables with readable characters

The packed decimal format is just that: a format. use any other format you want, such as 32.15, to write out the number in a human-legible form. I suspect the table's metadata may store an appropriate format for each variable.

Solution
‎11-18-2016 01:25 PM
Super User
Posts: 7,832

Re: PUT ZD and PD variables with readable characters

Use 16.2 instead of PD7.2.

With the ZDw, add 1 to the length for formats with no fractions, 2 for formats with fractions.

(ZD13.2 -> 15.2, ZD4.0 -> 5.0)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 221 views
  • 0 likes
  • 3 in conversation