Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to combine two variables data into two rows in SAS

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading