我们在sas数据集中有三个变量,我们想创建一个新的变量,该变量的值将被转换为两个变量,第三个变量保持原样。
例如:
Acct_nb repl_acct_nb amount
12334 45678 100
23456 . 200
所需输出:
new_acct_nb amount
12334 100
45678 100
23456 200
我想这就是你想要的。因为,它只有2个变量,不需要数组逻辑。
data have;
input Acct_nb repl_acct_nb amount;
datalines;
12334 45678 100
23456 . 200
;
data want(keep = new_acct_nb amount);
set have;
new_acct_nb = Acct_nb;
if new_acct_nb then output;
new_acct_nb = repl_acct_nb;
if new_acct_nb then output;
run;
您可以按照以下进行基于数组的换位
data want(keep=new_acct_nb amount);
attrib new_acct_nb length=8;
set have;
array account acct_nb repl_acct_nb;
do over account;
if missing(account) then continue;
new_acct_nb = account;
output;
end;
run;