We have three variables in sas dataset and we want to create a new variable which would have values transposed for 2 variables and the third remain as it is.
Eg:
Acct_nb repl_acct_nb amount
12334 45678 100
23456 . 200
Output needed:
new_acct_nb amount
12334 100
45678 100
23456 200
CodePudding user response:
I think this is what you want. Since, it is only 2 variables, no need for array logic.
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;
CodePudding user response:
You can do an array-based transposition as follows
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;