简体   繁体   中英

How to merge two variables in a Dataset using SAS

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   |

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM