Problems
(loop for number1 in sublist
for number2 in listB
when (= number1 number2)
do (setq candidate_sublist sublist)
finally (return candidate_list))
As soon as two number matches in your list, you replace candidate_sublist, even if it is worse than the previous binding. Suppose candidate_sublist is (0 2 3), which is equal to the input list (you can't be more similar than that). Then, you iterate over the next candidate which is (0 9 9). With your code, since (= 0 0), you change candidate_sublist. You really have to inspect all values in both lists being compared before making a decision.
Distance function
You are trying to define a comparison function among lists: a list is better than another one if it is more similar to the given list. This can be implemented by relying on a distance function.
The following one is good enough:
(defun distance (a b)
(count nil (mapcar #'= a b)))
Or, with a loop:
(defun distance (a b)
(loop
for aa in a
for bb in b
count (/= aa bb)))
Thus, the more difference there is among two lists, the higher the distance is.
Partial orders
This comparison, however, defines a partial order, because you can easily have two lists that are equally close to the input.
For exampe, given the following list:
(0 1 2)
Both (1 1 2) and (0 1 1) have the same number of matching values.
You cannot just return a single best answer, or else you are going to choose one based on an arbitrary criterion (e.g. an implementation detail, like the traversal order of your lists).
What I would do is compute all lists that are at an equal distance to the input list.
(defun closest-lists (list candidates)
(loop
for candidate in candidates
for distance = (distance list candidate)
for better = T then (< distance min-distance)
for min-distance = (if better distance min-distance)
for best-matches = (cond
(better (list candidate))
((= distance min-distance) (cons candidate best-matches))
(t best-matches))
finally (return (values best-matches min-distance))))
Generalization
As said in comments by @Gwang-Jin Kim, the closest-lists function can even be used with other distance functions if we add it as a parameter. Following the naming convention from sort, we could define a predicate argument to specify the comparison function, and a key argument to specify how to retrieve the values to be compared (the score). Then, our function is actually no more related to lists, and can be renamed to be more general:
(defun filter-by-score (candidates predicate &key (key #'identity))
"Keep elements from CANDIDATES having the same best rank according to PREDICATE.
PREDICATE should return non-NIL if its first argument precedes its
second one. Elements are compared according the value returned by
applying KEY. The KEY function is guaranteed to be applied once only
for each element in CANDIDATES."
(loop
for candidate in candidates
for score = (funcall key candidate)
for better = T then (funcall predicate score best-score)
for best-score = (if better score best-score)
for best-items = (cond
(better (list candidate))
((funcall predicate best-score score) best-items)
(t (cons candidate best-items)))
finally (return (values best-items best-score))))
Then, our previous function could be expressed as:
(filter-by-score candidates #'< :key (lambda (u) (distance list u)))
But we can also do:
CL-USER> (filter-by-score '("a" "ab" "cd" "ed" "fe" "aaa" "bbb" "nnn")
#'> :key #'length)
("nnn" "bbb" "aaa")
3
Or even:
CL-USER> (import 'alexandria:curry)
CL-USER> (ql:quickload :levenshtein)
CL-USER> (filter-by-score '("boat" "baobab" "brain" "biscuit")
#'<
:key (curry #'levenshtein:distance "ball"))
("brain" "boat")
3