Here's a start, below. This probably is NOT what you want, at least not completely. I'm just trying to give you some ideas.
1. I have joined the IF statements together with an ELSE so that they are mutually exclusive.
2. I have a final ELSE so that if no condition is met, we'll see an "unkn" (unknown) in the results so at least we'll know what's going on.
3. I coded an action for 'ES'. This may be what you want, so correct as necessary.
4. As an example, I broke apart the Department and the Dpt IF statements for LM/HRLD. The way they were, if the Dpt was missing, you got nothing. I set up a default in the case that the Dpt is not 16. This may not be what you want; this is just an example.
In an IF statement, you need to handle every possible combination of conditions -- and handle what happens if none of the conditions are met.
The results are below the code. Note that now all the rows have Department1 populated.
data Want;
length Department1 $ 4 Dpt1 8;
format Department1 $char4.;
set Have;
by StudentUID Term;
if Department in ('LM','HRLD') then do;
IF Dpt = 16 then
do;
Department1 = 'HRLD';
Dpt1=16;
end;
else
do;
Department1 = Department;
Dpt1 = Dpt;
end;
end;
ELSE
if Department in ('IPG') then do;
Department1 = 'IPG';
Dpt1=22;
end;
ELSE
if Department in ('PT','PT2','PTD') then do;
Department1 = 'PT';
Dpt1=53;
end;
ELSE
IF Department = 'ES' THEN
DO;
Department1 = 'ES';
Dpt1 = 54;
END;
ELSE
DO;
Department1 = 'Unkn';
Dpt1 = 99;
END;
run;
Jim
... View more