SAS 转置和总结

SAS Transpose and summarize

我正在 SAS 中处理以下场景。

输入 1

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

输出 1

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

输入 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

输出 2

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

我设法从输出 1 获得输入 2,现在只需要输出 2。

非常感谢您的帮助。

谢谢!

试试这个,将 [Input 2] 替换为您的 Input 2 table 的实际名称。

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