Students take 4 tests and a final exam. I replace the lowest test grade with the final exam grade. If the final exam is the lowest grade, nothing happens. If there is a tie between the 2 lowest grades, I don't care which one involved in the tie gets replaced.
Example:
data before applying the substitution
test1 test2 test3 test4 final
88 90 100 50 75
90 55 70 100 50
data after applying the substitution
test1 test2 test3 test4 final
88 90 100 75 75
90 55 70 100 50
Hi @GreggB,
Try this:
data have;
input test1-test4 final;
cards;
88 90 100 50 75
90 55 70 100 50
;
data want;
set have;
array g[*] test1--final;
g[whichn(min(of g[*]), of g[*])]=final;
run;
Hi @GreggB,
Try this:
data have;
input test1-test4 final;
cards;
88 90 100 50 75
90 55 70 100 50
;
data want;
set have;
array g[*] test1--final;
g[whichn(min(of g[*]), of g[*])]=final;
run;
I would want to replace one of them. It wouldn't matter which one.
what if there are two 50 in the first obs ?
data have; input test1-test4 final; cards; 88 90 100 50 75 90 55 70 100 50 ; data want; set have; array g{*} test1--test4; do i=1 to dim(g); g{i}=max(g{i},final) ; end; drop i; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.