0

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

2 Answers 2

0

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;
0
0

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.