просто используйте формат proc, это просто и понятно.
data have;
input name $ prof_grade $ TA_grade $ chair_grade $;
datalines;
Anne A+ A A+
Peter B+ B+ AAA
Pete A+ A- AA
;
/* your lookup table for creating informats*/
data lookup;
input Score Rating $ Teacher $;
datalines;
10 A+ prof
10 A TA
10 AAA chair
9 A prof
9 A- TA
9 AA chair
8 B+ prof
8 B+ TA
8 A+ chair
;
/* creating informat*/
proc sql ;
create table crfmt as
select distinct
Teacher as fmtname,
strip(Rating) as start,
score as label,
"J" as type
from lookup;
quit;
proc format library=work cntlin=crfmt fmtlib;
run;
/* using the informat created in the table above in first 2 cases score are
character values you need to use one more input change to number as shown below*/
data want;
set have;
Prof_score = input(trim(prof_grade),$prof.);
TA_score = input(trim(TA_grade),$TA.);
/* to make it numeric value*/
chair_score = input(input(trim(chair_grade),$chair.),best32.);
run;
Edit1: если вы хотите обратиться к другим значениям.пожалуйста, используйте код ниже
data have;
input name $ prof_grade $ TA_grade $ chair_grade $;
datalines;
Anne A+ A A+
Peter B+ B+ AAA
Pete A+ A- AA
Smith A+ A- AAA1A
;
/* your lookup table for creating informats*/
data lookup;
infile datalines missover;
input Score $ Rating $ Teacher $;
datalines;
10 A+ prof
10 A TA
10 AAA chair
9 A prof
9 A- TA
9 AA chair
8 B+ prof
8 B+ TA
8 A+ chair
;
/* insert rows in lookup to address other values*/
proc sql;
insert into lookup
values(" ", "Unknown" , "chair");
insert into lookup
values(" ", "Unknown" , "TA");
insert into lookup
values(" ", "Unknown" , "prof");
/* creating informat*/
proc sql ;
create table crfmt as
select distinct
Teacher as fmtname,
strip(Rating) as start,
score as label,
"J" as type
from lookup;
quit;
proc format library=work cntlin=crfmt fmtlib;
run;
/* using the informat created in the table above in first 2 cases score are
character values you need to use one more input change to number as shown below*/
data want;
set have;
if input(trim(prof_grade),$prof.) eq prof_grade
then prod_score = ' ';
else prod_score = input(trim(prof_grade),$prof.);
;
if input(trim(TA_grade),$TA.) eq TA_grade
then TA_score = ' ';
else TA_score = input(trim(TA_grade),$TA.);
if input(trim(Chair_grade),$chair.) eq Chair_grade
then chair_score = ' ';
else chair_score = input(trim(chair_grade),$chair.);
run;