Thursday, November 10, 2022

[FIXED] how to combine two variables data into two rows in SAS

Issue

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

Solution

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;


Answered By - PeterClemmensen
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.