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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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