How can i merge 2 variable if the one ofthem is null
id work number
5 0
4
8 1 1-2
9 2 2-5
i want to change as if the number is null merge with 'work'
id work number
5 0 0
4
8 1 1-2
9 2 2-5
Do you have any code that you're currently trying? It's not clear to me if you want to merge on all three variables or just the first two and you want to figure out how to deal with third.
if the 'number' is null and 'work' has variable, add that variable to the 'number' by 'id'. Is that clear?
Not entirely, but I can be a bit daft. But from what I understand, you could try:
if not missing(work) then number = coalescec(number, '0');
Or if you mean that you want to populate 'number' with 'work,' you could do:
number = coalescec(number, work);
I'm not sure about what the variable types are, though.
I have chracter variable. Also you can think like its left join . i only want to take if the work has variable and number doesn;t have variable.
id work number
11 2 2
12
13 3 3
15 1 1-2
16 2 2-3
So i have the table without red variables. I want the table with red variables
Like this?
data have;
infile datalines dsd;
input id work $ number $;
datalines;
11, 2,
12, ,
13, 3,
15, 1, 1-2
16, 2, 2-3
;
data want;
set have;
number = coalescec(number, work);
run;
Isn't this simply:
if number = ' ' then number = work;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.