我想转置一个表从长到宽,但我有多个值为每个密钥。我希望转置表对每个Id和Key的组合都有一行,所以对于这个示例项目,我将在转换后有8行。 Id变量将被保留,每个不同的Key将是同一个键的所有不同值的组合。所以2 * 2 * 1 * 1 * 1 * 2 = 8行。转置保留所有组合的多个值为变量的变量在SAS
data grades;
input Id Key $ Value $;
cards;
219381 Category Something
219381 Category Another
219381 Color White
219381 Color Black
219381 Sport Football
219381 Gender Male
219381 Size Big
219381 Quality Good
219381 Quality Bad
;
run;
这是我想这个复杂的换位之后出来什么:
Id Category Color Sport Gender Size Quality
219381 Something White Football Male Big Good
219381 Something White Football Male Big Bad
219381 Something Black Football Male Big Good
219381 Something Black Football Male Big Bad
219381 Another White Football Male Big Good
219381 Another White Football Male Big Bad
219381 Another Black Football Male Big Good
219381 Another Black Football Male Big Bad
任何想法如何,我可以做到这一点? 我已经尝试了许多事情,但都没有成功。
我认为SASsy解决这个问题的方法是HOH(Hash of Hashes)。我现在没有时间写一篇文章,因为这篇文章经常不足以记住我的头顶。但是,http://support.sas.com/resources/papers/proceedings11/255-2011.pdf将是一个好的开始,如果我有一些时间,我会回来写下来。 – Joe
@Joe,如果您可以将您的SASsy解决方案与HoHs一起发布,我认为这将非常具有启发性(不仅适用于我)。 –