Hi...I am trying to change certain Department entries. Each record represents a course and courses may be taken from different departments. In order to identify the program that the student is enrolled in, I need to group the courses for each student to the appropiate Department which will identify the program of study. Because some courses are not counted or used as credit toward the students program, I have to identify which Department entries that are to be changed. From the code below that I have so far, the changes are being made. Any suggestion or revision would be greatly appreciated.Thanks.
data Have;
length 'Academic Year'n $ 9 StudentUID 8 Department $ 4;
format 'Academic Year'n $char9. StudentUID best12. Department $char4.;
informat 'Academic Year'n $char9. StudentUID best12. Department $char4.;
infile datalines4 dlm='7f'x missover dsd;
input 'Academic Year'n : $char9. StudentUID : best32. Department : $char4.;
datalines4;
2017-2018 83136 CAR
2017-2018 83136 CAR
2017-2018 83136 CT
2017-2018 83136 YB
2017-2018 83136 YB
2017-2018 83136 YBC
2017-2018 83136 CAR
2017-2018 88069 NCT
2017-2018 88069 NCT
2017-2018 88069 ES
2017-2018 88069 CDCA
2018-2019 83882 MOA
2018-2019 83882 MOA
2018-2019 83882 RH
2018-2019 83882 RH
2018-2019 83882 RH
2018-2019 83882 MOA
2018-2019 83882 MOA
2018-2019 83882 MOA
2018-2019 83882 ES
2018-2019 83882 ES
2019-2020 86518 RH
2019-2020 86518 RH
2019-2020 86518 MAA
2019-2020 86518 MAA
2019-2020 86518 MAA
2019-2020 86518 ES
2019-2020 86518 ES
2019-2020 86519 IB
2019-2020 86519 IB
2019-2020 86519 IB
2019-2020 86519 LM
2019-2020 86519 LM
2019-2020 86519 IB
;;;;
proc sort data=Have;
by 'Academic Year'n StudentUID;
run;
data Want;
set Have;
by 'Academic Year'n StudentUID;
length Department1 $ 4.;
retain Dpt;
if findw(Department,'YBC')>0 then do;
Dpt = 'YBC';
if Department in ('YBC','YB','CT','CAR') then
Department1 = DPT;
else
Department1 = Department;
drop Dpt;
end;
if findw(Department,'CDCA')>0 then do;
Dpt = 'CDCA';
if Department in ('CDCA','NCT') then
Department1 = DPT;
else
Department1 = Department;
drop Dpt;
end;
if findw(Department,'MOA')>0 then do;
Dpt = 'MOA';
if Department in ('MOA','RH') then
Department1 = DPT;
else
Department1 = Department;
drop Dpt;
end;
if findw(Department,'MAA')>0 then do;
Dpt = 'MAA';
if Department in ('MAA','RH') then
Department1 = DPT;
else
Department1 = Department;
drop Dpt;
end;
if findw(Department,'IB')>0 then do;
Dpt = 'IB';
if Department in ('IB','LM') then
Department1 = DPT;
else
Department1 = Department;
drop Dpt;
end;
run;
Want:
Academic Year StudentUID Department Department1
2017-2018 83136 CAR YBC
2017-2018 83136 CAR YBC
2017-2018 83136 CT YBC
2017-2018 83136 YB YBC
2017-2018 83136 YB YBC
2017-2018 83136 YBC YBC
2017-2018 83136 CAR YBC
2017-2018 88069 NCT CDCA
2017-2018 88069 NCT CDCA
2017-2018 88069 ES ES
2017-2018 88069 CDCA CDCA
2018-2019 83882 MOA MOA
2018-2019 83882 MOA MOA
2018-2019 83882 RH MOA
2018-2019 83882 RH MOA
2018-2019 83882 RH MOA
2018-2019 83882 MOA MOA
2018-2019 83882 MOA MOA
2018-2019 83882 MOA MOA
2018-2019 83882 ES ES
2018-2019 83882 ES ES
2019-2020 86518 RH MAA
2019-2020 86518 RH MAA
2019-2020 86518 MAA MAA
2019-2020 86518 MAA MAA
2019-2020 86518 MAA MAA
2019-2020 86518 ES ES
2019-2020 86518 ES ES
2019-2020 86519 IB IB
2019-2020 86519 IB IB
2019-2020 86519 IB IB
2019-2020 86519 LM IB
2019-2020 86519 LM IB
2019-2020 86519 IB IB
... View more