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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.