我想将表格从长转换为宽,但每个键都有多个值。我希望转置表对于 Id 和 Key 的每个组合都有一行,因此对于此示例项目,我在转置后将有 8 行。将保留 Id 变量,每个不同的键将是同一键的不同值的所有组合。所以 2 * 2 * 1 * 1 * 1 * 2 = 8 行。
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
有什么想法可以实现这一目标吗?我尝试了很多事情都没有成功。