Reading and writing MicroFocus COBOL data


MicroFocus COBOL data is similar to standard zoned decimal numeric data in that the last byte is a letter or symbol that contains the value's sign along with the last digit. MicroFocus COBOL data is signed only if it is negative. The last character conforms to this layout:

  p=0     u=5
  q=1     v=6
  r=2     w=7
  s=3     x=8
  t=4     y=9

For example, in MicroFocus Cobol the value -123 is written as 12s.

Beginning in SAS 9.2, a new informat VMSZNw.d reads this type of data.
Prior to SAS 9.2, this data can be read on VMS with the VMSZNw.d informat. On other operating systems, values can be read using the following sample code:

                                                                  
  data _null_;                                                         
    input mfc $char6.;                                                 
    len=length(mfc);                                                   
    substr(mfc,len,1)=translate(substr(mfc,len,1),                     
      '{ABCDEFGHI}JKLMNOPQR',                                          
      '0123456789pqrstuvwxy');                                         
    n=input(mfc,zd6.);                                                 
  put n=;                                                              
  cards;                                                               
  543210                                                               
  543211                                                               
  543212                                                               
  543213                                                               
  54321p                                                               
  54321q                                                               
  54321r                                                               
  54321s                                                               
  ;                                                                    
  run;  


Full Code

As of SAS 9.2, the VMSZNw.d informat can read MicroFocus COBOL data. The last position of the number is a letter that represents the last digit of the value as well as the sign of the value.

/* The 'y' in the last position represents a 9 and makes the entire 
value negative */

data a;
infile datalines truncover;
input x vmszn5.;
datalines;
1234y
;
proc print;run;


Output

Obs       x

1     -12349