Ksharp, Thanks for your reply. but I'm more confused.thus I put the original code about 10%, I'm wondering whether your method can be applied in the following way? PROC SQL /*Generate vertical data, duplicated*/; CREATE TABLE wutemp.CustDemoHistory AS /*Age*/ SELECT t1.branch_code,t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version,t1.'New Cust Ind'n, t1.OccupationCMP,t1.AGECMP as cmp, (COUNT(t1.AgeCMP)) as NoCount,trblevel,zoneCMP,agecmp FROM wutemp.CUSTDEMOBASEHistory AS t1 GROUP BY t1.branch_code, t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, trblevel,zoneCMP,agecmp /*Sex*/union SELECT t1.branch_code,t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp,version, t1.'New Cust Ind'n, t1.OccupationCMP, T1.'Sex Code'n as CMP , (COUNT(*)) AS NoCount,trblevel,zoneCMP,agecmp FROM wutemp.CUSTDEMOBASEHistory AS t1 GROUP BY t1.branch_code, t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, trblevel , t1.'Sex Code'n,zoneCMP,agecmp /*TRBCount*/union SELECT t1.branch_code,t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, trblevel as CMP , (COUNT(*)) AS NoCount,trblevel,zoneCMP,agecmp FROM wutemp.CUSTDEMOBASEHistory AS t1 GROUP BY t1.branch_code, t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, trblevel,zoneCMP,agecmp /*Vintage*/union SELECT t1.branch_code,t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, Vintage as CMP , (COUNT(*))AS NoCount,trblevel,zoneCMP,agecmp FROM wutemp.CUSTDEMOBASEHistory AS t1 GROUP BY t1.branch_code, t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, trblevel , Vintage,zoneCMP,agecmp /*SATRBCount*/ union SELECT t1.branch_code,t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP,t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, T1.SAtrblevel as CMP , (COUNT(*)) AS NoCount,trblevel,zoneCMP,agecmp FROM wutemp.CUSTDEMOBASEHistory AS t1 GROUP BY t1.branch_code, t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, trblevel , SAtrblevel,zoneCMP,agecmp /*TRBSUM*/union SELECT t1.branch_code,t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, (Case WHEN t1.TRBLevel ='TRB1:0_10K' THEN 'TRB9_1:0_10K' WHEN t1.TRBLevel='TRB2:10k_100K' THEN 'TRB9_2:10k_100K' WHEN t1.TRBLevel ='TRB3:100k_300K' THEN 'TRB9_3:100k_300K' WHEN t1.TRBLevel ='TRB4:300k_1M' THEN 'TRB9_4:300k_1M' WHEN t1.TRBLevel='TRB5:1M_3M' THEN 'TRB9_5:1M_3M' WHEN t1.TRBLevel= 'TRB6:3M_5M' THEN 'TRB9_6:3M_5M' WHEN t1.TRBLevel= 'TRB7:Over5M' THEN 'TRB9_7:Over5M' else 'TRB9_8:Nill' End ) as CMP , (sum('Last Month Average Balance'n)) AS NoCount,trblevel,zonecmp,agecmp FROM wutemp.CUSTDEMOBASEHistory AS t1 GROUP BY t1.branch_code, t1.'PFS Cust Segment Code'n, LoanCMP,OutstandingCMP, t1.nationcmp, version, t1.'New Cust Ind'n, t1.OccupationCMP, trblevel , SAtrblevel,zoneCMP,agecmp
... View more