As part of a large data set, 2 of my columns need to be combined with observations (from column A) replacing blanks (in column B), while at the same time having all observations from column B stay in the final output. To clarify further all observations from column A with the value "9" (only this value) need to be replaced by whatever is in Column B in the final output.
Here is an example data:
ID Column A Column B Desired output
A1 1 . 1
A2 3 . 3
A3 4 . 4
A4 9 7 7
A5 9 7 7
A6 4 . 4
A7 6 . 6
A8 1 . 1
A9 9 8 8
Thanks!
Hi are you asking for an if then?
data want;
set have;
colb=coalesce(colb,col_a);
desired=ifn(col_a=9,colb,col_a);
run;
Hi are you asking for an if then?
data want;
set have;
colb=coalesce(colb,col_a);
desired=ifn(col_a=9,colb,col_a);
run;
It worked. Thank you very much!
data sample;
infile datalines dlm=' ' dsd;
input ID $ Column_A Column_B Desired_output;
want=ifn(Column_A=9,Column_B,Column_A);
datalines;
A1 1 . 1
A2 3 . 3
A3 4 . 4
A4 9 7 7
A5 9 7 7
A6 4 . 4
A7 6 . 6
A8 1 . 1
A9 9 8 8
;
run;
Perhaps your test data does not show the actual complexity?
Looks like you just want to use the COALESCE() function.
want = coalesce(B,A);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.