Page 1 of 1

calculate the age of a customer

PostPosted: Tue Jun 28, 2011 4:17 pm
by javivi
Hi

I have a file with the date (YYYYMMDD) of a customer and I need to know his age.

I'm trying some test with DATEDIFF etc but I can't ....

Can someone help me?

Re: calculate the age of a customer

PostPosted: Tue Jun 28, 2011 5:08 pm
by NicC
What have you tried? What does your input look like? Is it FB/VB? Where in the record is the date field?

Re: calculate the age of a customer

PostPosted: Tue Jun 28, 2011 5:21 pm
by javivi
Sorry for my bad explanation..:-(

I have a FB file with 80 lrecl.
KEY BIRD DATE
000000000119600416
000000000219570723

(KEY 10 numeric pos.,
(BIRTH DATE 8 numeric pos, in YYYYMMDD format)

I'v tried to use datediff but this give me the days between the birh date and system date and I need to know the years old.,. 50 years, 27 year etc..)


Now I tried the simple: 11,8,sub,+2011028) but it seems a not a very good idea....

Thanks

Re: calculate the age of a customer

PostPosted: Tue Jun 28, 2011 9:03 pm
by skolusu
Javivi,

Sort products do not have any built-in functions to calculate the age. Datediff function gives the date difference in the number of days .

Do you need the age as

1. 51 years 2 months 12 days
2. 51 years 73 days
3. 51 years

Option 2 and 3 are easy with a bunch of ifthen statements

Re: calculate the age of a customer

PostPosted: Wed Jun 29, 2011 11:58 am
by javivi
HI

The option 2 or 3 is enough.

Thanks.

Re: calculate the age of a customer

PostPosted: Wed Jun 29, 2011 11:15 pm
by skolusu
javivi wrote:HI

The option 2 or 3 is enough.

Thanks.


Javivi,

The following DFSORT JCL will give you the desired results. I assumed your input as FB RECFM and LRECL of 80.

If the date of birth is invalid (ex : feb 29 of 2001 ) or if the date of birth is greater than current date , age is not calculated.
//STEP0100 EXEC PGM=SORT                                       
//SYSOUT   DD SYSOUT=*                                         
//SORTIN   DD *                                                 
----+----1----+----2----+----3----+----4----+----5----+----6----
000000000119600416                                             
000000000219570723                                             
000000000320110228                                             
000000000320110630                                             
000000000420010229                                             
//SORTOUT  DD SYSOUT=*                                         
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                             
  INREC IFOUTLEN=80,IFTHEN=(WHEN=INIT,OVERLAY=(81:DATE1)),     
  IFTHEN=(WHEN=(81,6,ZD,GE,11,6,ZD,AND,17,2,ZD,LE,87,2,ZD),     
  OVERLAY=(090:81,4,ZD,SUB,11,4,ZD,EDIT=(TTTT),                 
           096:11,8,Y4T,ADDYEARS,90,4,ZD,TOGREG=Y4T),HIT=NEXT),
  IFTHEN=(WHEN=(96,1,ZD,EQ,NUM),                               
  OVERLAY=(105:81,8,Y4T,DATEDIFF,96,8,Y4T),HIT=NEXT),           
  IFTHEN=(WHEN=(105,1,CH,EQ,C'-'),                             
  OVERLAY=(090:(81,4,ZD,SUB,+1),SUB,11,4,ZD,EDIT=(TTTT),       
           096:11,8,Y4T,ADDYEARS,90,4,ZD,TOGREG=Y4T,           
           105:81,8,Y4T,DATEDIFF,96,8,Y4T),HIT=NEXT),           
  IFTHEN=(WHEN=(105,1,CH,GT,C' '),                             
  OVERLAY=(30:090,4,ZD,EDIT=(IIIT),C' YEARS AND ',             
              110,3,ZD,EDIT=(IIT),C' DAYS OLD'),HIT=NEXT),     
  IFTHEN=(WHEN=(105,1,CH,EQ,C' '),                             
  OVERLAY=(32:C'THE DATE OF BIRTH IS INVALID'))                 
//*


The output from this job is
000000000119600416             51 YEARS AND  74 DAYS OLD       
000000000219570723             53 YEARS AND 341 DAYS OLD       
000000000320110228              0 YEARS AND 121 DAYS OLD       
000000000320110630             THE DATE OF BIRTH IS INVALID   
000000000420010229             THE DATE OF BIRTH IS INVALID