Without having any actual value it is likely because you are reassigning values.
 
Try this:
Data SSN1;
   set ssn;
   if lastfour_ssn = 0 then SSN = 1;
   else if lastfour_ssn = 9999 then ssn= 2;
   else if lastfour_ssn >9999 or (0< lastfour_ssn<1000) then ssn=3;
   else if lastfour_ssn= . then ssn= 4;
   else ssn=5;
run;
You code when it got to the comparison for missing and they weren't went to assign every thing to 5.
If the 1, 2, or 3 codes are assigned you do not want to check if it the value is missing.
Edited the SSN=3.   MISSING is less than anything so without a restriction you would never get the 4 result.