Example using RETAIN, DO, ARRAY and More
DATA SCORING;
ARRAY KEY[5] $ 1 KEY1-KEY5; * ANSWER KEY ;
ARRAY ANS[5] $ 1 ANS1-ANS5; * STUDENT RESPONSES ;
ARRAY SCORE[5] SCORE1-SCORE5; * ITEM SCORES, ;
* 1=CORRECT, ;
* 0=WRONG ;
RETAIN KEY1-KEY5;
IF _N_=1 THEN DO;
INPUT (KEY1-KEY5)($1.);
DELETE;
END;
ELSE DO;
INPUT (ANS1-ANS5)($1.);
DO I=1 TO 5;
IF KEY[I]=ANS[I] THEN SCORE[I]=1;
ELSE SCORE[I]=0;
END;
RAW=SUM (OF SCORE1-SCORE5);
PERCENT=(100*RAW)/5;
END;
KEEP RAW PERCENT;
DATALINES;
ABCDE
ABABA
ABCDA
;
PROC PRINT DATA=SCORING;
TITLE1 "Scoring a Test";
RUN;