【问题标题】:Using SAS to group column values into discrete variables使用 SAS 将列值分组为离散变量
【发布时间】:2020-11-12 16:53:27
【问题描述】:
我基本上有这样一张桌子:
X1 X2 X3 Y1 Y2 Y3
A
B
C
D
E
所有这些列都有“C71”或“D38”之类的代码,我希望能够转换所有“C71”= 1 和所有“D38”、“H80”、“C91”= 2 等我可以将具有相似含义的代码分组到所有列中的单个数字或变量中,而不是查看许多不同的代码。
谢谢。
【问题讨论】:
标签:
python
database
dataframe
sas
statistics
【解决方案1】:
改用数组。
data want;
set have;
array orig(*) x1-x3 y1-y3;
array recoded(*) z1-z6;
do i=1 to dim(orig);
if orig(i) in ('C71', 'D38') then recoded(i)=1;
else if orig(i) in ('D38', 'H80', 'C91') then recoded(i) = 2;
end;
run;
另一种选择是使用格式,但这实际上取决于您在下一步中尝试做什么。