Home > Mobile >  How to merge two variables in a Dataset using SAS
How to merge two variables in a Dataset using SAS

Time:03-18

I have a dataset from an imported file.
Now there are two variables that need to be merged into one variable because the data is identical.
arr and arr_nbr should be merged into arr_nbr.

How can I get that done?

Original:

|name |db      |arr |arr_nbr|
 ----- -------- ---- ------- 
|john |10121960|0456|       |
|jane |04071988|    |8543   |
|mia  |01121955|9583|       |
|liam |23091973|    |7844   |

Desired output:

|name |db      |arr_nbr|
 ----- -------- ------- 
|john |10121960|0456   |
|jane |04071988|8543   |
|mia  |01121955|9583   |
|liam |23091973|7844   |

CodePudding user response:

Given that there are leading 0's in your desired output, I assume they are all character variables. In that case, use the COALESCEC function. It returns the first non-null or nonmissing value.

data want;
    set have;
    arr_nbr = coalescec(arr, arr_nbr);
    drop arr;
run;
 name     db     arr_nbr
 john  10121960   0456
 jane  04071988   8543
 mia   01121955   9583
 liam  23091973   7844
  • Related