BookmarkSubscribeRSS Feed
Lulus
Obsidian | Level 7

So I have this question. 
I need to do a repetitive steps, I have 5 kind of fruit f1-f5 indicating the amount of suger in it and

if f1>max(f2,f3,f4,f5) then label=one;
else if f2>max(f1,f3,f4,f5) then label=two;
else if f3>max(f1,f2,f4,f5) then label=three;
else if f4>max(f2,f3,f4,f5) then label=four;
else if f5>max(f1,f2,f3,f4) then label=five;


if (f1+f2)<=10 and max(f3,f4,f5)<20 then label=type2one;
else if (f1+f3)<=10 and max(f2,f3,f4)<20 then label=type2one;
else if (f1+f4)<=10 and max(f2,f3,f4)<20 then label=type2two;
else if (f1+f5)<=10 and max(f2,f3,f4)<20 then label=type2three;

else if (f2+f3)<=10 and max(f3,f4,f5)<20 then label=type2four;
else if (f2+f4)<=10 and max(f3,f4,f5)<20 then label=type2five;

..................and on and on;

but basically there is a rule that for "single fruit" case,you just exclude the one used up frount and
for for the "two fruit" case, you exlcude whatever two mentitoned first,

So I hope to do something like,

array fruit1 {*} f1 f2 f3 f4 f5
array fruit2 {*} f1 f2 f3 f4 f5


do i=1 to 5;
if fruit(i)>max(fruit but fruit(i))

        if fruit(i))+fruit(i+1))<=10 and max(fruit but (fruit(i) ,fruit(i+1))) ;
          *<- here I have another problem though, i is supposed from 1 to 5 but here it will be ended with 6 not really that I want;


Please let me know how do you do it.  Appreiciate your help.

2 REPLIES 2
Astounding
PROC Star

Lulus,

I'm not sure that your logic will handle a tie for the top spot, or that you are assigning the proper values to LABEL, but here are some ideas.

To handle one variable you could simplify things in this fashion:

max_value = max(of f1-f5);

do _i_=1 to 5;

   if fruit1{_i_} = max_value then label=put(_i_, 1.);

end;

Handling two variables is harder.  Here's one way to approach the problem:

do _i_=1 to 4;

   do _j_ = _i_+1 to 5;

      max_value = 0;

      do _k_=1 to 5;

          if (_k_ ne _i_) and (_k_ ne _j_) then max_value = max(max_value, fruit1{_k_};

      end;

      if fruit1{_i_} + fruit1{_j_} <= 10 and max_value < 20 then label = put(_i_,1.) || ' ' || put(_j_, 1.);

   end;

end;

It doesn't do exactly what you started to explain, but it's difficult to tell what result you wanted to obtain for LABEL.  At any rate, this gives you a way to identify the cases you were looking for.

Good luck.

Lulus
Obsidian | Level 7

Thnak you!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 539 views
  • 3 likes
  • 2 in conversation