set table2 key = depcode;
if (not _iorc_ = %sysrc(_sok)) then do;
Department = ' ' ;
errtxt = " ";
_error_ = 0;
Sorry, no parentheses needed there (Code off the top of my head may sometimes contain syntax errors).
This should give you the starting point to solve your problem.
You could also use the data set "department" to create a format (example in SAS OnlineDoc for Proc Format) and then apply this format in the Individuals table on the field "DepCode".
If you need the department names for printing only this would avoid to create redundant data in a second table (using a format statement). If you still would want to create a new variable: DepartmentName=put(depcode,depfmt.);
proc sql noprint;
create table individuals2 as
from individuals ind left join department dep
Suggest you reply to the group with SASLOG output revealing your SAS DATA and PROC step execution adjacent to the failing DATA step, also showing the error message you receive. The critical contributing factor here is the location of your KEY= parameter on the SET statement - something the DOC can help convey.
An executable example.
NOTE: you need to have an index on the lookup set, and you need to handle errors where there is no match. For small cases the format that Patrick refered to is great, but when you get into very large lookups this method is better.