我有以下数据集:
data abc;
infile xyz;
input test $9;
q1 $3
q2 $3
.
qn $3;
我想创建一个循环,允许在所有那些'q'变量上检查特定条件(如果前两个字符不是07那么),然后获得满足该条件的所有'test'变量。< / p>
我一直在尝试这个
data loop;
set abc;`
array q{15};`
if substri(q{15},1,2) = "07" then do;`
run;
输入看起来像这样
test q1 q2 q3........qn
cust1 0000 0700 0800 0700
cust2 0000 0700 0800 0900
cust3 0000 0000 0800 0900
cust 4 0700 0000 0800 0900
根据我想为前两个字符为07的情况设置测试列的条件。结果应为
test q1 q2 q3........qn
cust1 ---- 0700 ---- 0700
cust2 ---- 0700 ---- ----
cust 4 0700 ---- ---- ----
答案 0 :(得分:0)
假设您希望在输入数据集中前两个字符为07时q1-qn
中缺少值,则可以执行以下操作:
data want;
set have;
array q{15} $;
output_flag = 0;
do i = 1 to 15;
if q[i] eq: '07' then output_flag + 1;
else call missing(q[i]);
end;
drop i;
if output_flag then output;
run;
答案 1 :(得分:0)
你几乎得到了答案 - 只需按照你的if语句进行操作:
data loop;
set abc;
array q{15} $;
do i = 1 to 15;
if substri(q{i},1,2) = "07" then do;
q{i} = q{i};
else
q{i} = "";
end;
end;
run;