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);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.