Search code examples
sqlsastransposesummaryenterprise-guide

SAS Transpose and summarize


I'm working on following scenario in SAS.

Input 1

AccountNumber   Loans
123             abc, def, ghi
456             jkl, mnopqr, stuv
789             w, xyz

Output 1

AccountNumbers  Loans
123             abc
123             def
123             ghi
456             jkl
456             mnopqr
456             stuv
789             w
789             xyz

Input 2

AccountNumbers  Loans
123             15-abc
123             15-def
123             15-ghi
456             99-jkl
456             99-mnopqr
456             99-stuv
789             77-w
789             77-xyz

Output 2

AccountNumber   Loans
123             15-abc, 15-def, 15-ghi
456             99-jkl, 99-mnopqr, 99-stuv
789             77-w, 77-xyz

I manged to get Input 2 from output 1, just need Output 2 now.

I will really appreciate the help.

Thanks!


Solution

  • Try this, replacing [Input 2] with the actual name of your Input 2 table.

    data output2 (drop=loans);
        do until (last.accountnumbers);
            set [Input 2];
            by accountnumbers;
            length loans_combined $100;
            loans_combined=catx(', ',loans_combined,loans);
        end;
    run;