I am not sure I understand all of the details of the data and the transaction you want to perform.
As I read it you have a Customer (c) and a customer SSN (c_ssn) and the same for guarantor (g and g_ssn)
I assume you always have c and c_ssn but sometimes g and g_ssn don't exist? Or they do exist but, g being somehow identifiable as the same as c you need to pass the c_ssn rather than the g_ssn to the new database.
Is it something like that?
In your formula I don't understand where the 'lasts' and 'firsts' come from.
I think what you need is a calculated field that uses the input data, but not necessarily the g_ssn data field even if it is populated, and becomes the actual field you will use for g_ssn.
So if I refer to the new field as g_ssn_calc the formual would be something like;
So that means;
If g_ssn is blank, use c_ssn.
Otherwise, IF guarantor and customer are the same, use the c_ssn value.
If neither of the previous conditions are true, use the g_ssn value.
Assessing whether g=c may be a little more complex that shown above but that is a data issue and not an issue of the principle!
Your export should then use the new g_ssn_calc field and not the g_ssn field originally imported.
Does that make sense?