turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- exclude a varaible from an array? how to do it?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-11-2013 05:03 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Lulus

02-11-2013 10:34 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Astounding

02-12-2013 11:26 AM

Thnak you!!