Join Files on Country Code and Summarize

Input File 1 
US Smith    100
UK Jones     50
GR Alexander  1
GR Alexander  3
US Smith     39
ES James    890
Input File 2
ES Spain
UK United Kingdom
US United States
GR Greece
Sort Control Cards
 JOINKEYS FILE=F1,FIELDS=(1,2,A) * Customers
 JOINKEYS FILE=F2,FIELDS=(1,2,A) * Country Code file
 REFORMAT FIELDS=(F2:1,20,F1:4)  * Copy Country Info to Customers
 SORT FIELDS=(1,2,CH,A)          * After joining, sort by country code
 SUM FIELDS=(30,3,ZD)            * Sum the amount
 OUTREC FIELDS=(1,20,30,3)       * Include Country and Total
 END
Output File
ES Spain            890
GR Greece             4
UK United Kingdom    50
US United States    139
Back to Examples