我有1个数据与内容描述设置一个校 内容:SAS使用查找数据集像阵列中的另一个数据集
num description
content1 math
content2 spanish
content3 geography
content4 chemistry
content5 history
在另一个数据集
(学生)我有阵列内容1-content5和我使用标志来指示每个学生的内容。
学生
name age content1 content2 content3 content4 content5
BOB 15 1 1 1 1
BRYA 16
CARL 15 1 1
SUE 17 1 1 1
LOU 15 1
如果我使用这样的代码:
data students1;
set students;
array content[5];
format allcontents $100.;
do i=1 to dim(content);
if content[i]=1 then do;
allcontents=cat(vname(content[i]),',',allcontents);
end;
end;
run;
结果是:
name age content1 content2 content3 content4 content5 allcontents
BOB 15 1 1 1 1 content1,content2,content3,content5,
BRYA 16
CARL 15 1 1 content2,content5,
SUE 17 1 1 1 content3,content4,content5,
LOU 15 1 content5
1)我想使用的查找表的名称(数据集内容)使用内容的名称,而不是变量allcontents中内容[1-5]的数组名称。我怎样才能做到这一点?
2)后来我想要的结果,通过内容的描述,而不是由学生,像这样:
description name age
math BOB 15
spanish BOB 15
geography BOB 15
history BOB 15
spanish CARL 15
history CARL 15
spanish SUE 17
chemistry SUE 17
history SUE 17
history LOU 15
这可能吗?
谢谢。
不错,它的作品使用哈希很棒,谢谢! – user3142441