calculate the age of a customer



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

calculate the age of a customer

Postby javivi » Tue Jun 28, 2011 4:17 pm

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?
javivi
 
Posts: 47
Joined: Fri Jan 21, 2011 2:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: calculate the age of a customer

Postby NicC » Tue Jun 28, 2011 5:08 pm

What have you tried? What does your input look like? Is it FB/VB? Where in the record is the date field?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: calculate the age of a customer

Postby javivi » Tue Jun 28, 2011 5:21 pm

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
javivi
 
Posts: 47
Joined: Fri Jan 21, 2011 2:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: calculate the age of a customer

Postby skolusu » Tue Jun 28, 2011 9:03 pm

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
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
skolusu
 
Posts: 586
Joined: Wed Apr 02, 2008 10:38 pm
Has thanked: 0 time
Been thanked: 39 times

Re: calculate the age of a customer

Postby javivi » Wed Jun 29, 2011 11:58 am

HI

The option 2 or 3 is enough.

Thanks.
javivi
 
Posts: 47
Joined: Fri Jan 21, 2011 2:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: calculate the age of a customer

Postby skolusu » Wed Jun 29, 2011 11:15 pm

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   
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
skolusu
 
Posts: 586
Joined: Wed Apr 02, 2008 10:38 pm
Has thanked: 0 time
Been thanked: 39 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post