BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GreggB
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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;

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

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;
Ksharp
Super User
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;
GreggB
Pyrite | Level 9

I would want to replace one of them. It wouldn't matter which one.

Ksharp
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1547 views
  • 2 likes
  • 3 in conversation