Not applicable
Posts: 0

any simple way to find which one is min in a large set of variables?

I have var_1 to var_n, some are missing, now I need to find the smallest value. Once I know the min, then I need to find which variable achieves the min. I can write a loop to solve the problem. However, is there any function that can do the job in a simple way?
SAS Super FREQ
Posts: 9,365

Re: any simple way to find which one is min in a large set of variables?

Hi:

Consider this fake data:
[pre]
grp var_1 var_2 var_3
aaa 1 2 3
bbb . 3 4
ccc 1 0 .
ddd 0 0 0
[/pre]

would you need to find the MIN of all the VAR_1 values, all the VAR_2 values, all the VAR_3 values?? Or, would you need to find the MIN on the row for grp=aaa and then the MIN for grp=bbb, etc? Or, do you need to find out the minimum value for ALL the variables across the entire dataset?

Also, should the missing (.) be treated differently from the zero (0) values??

You can probably do quite a bit with PROC MEANS if you are looking for the MIN value across the whole dataset or based on classification variables (like GRP). You might have to use the MIN function in a DATA step program if you wanted to find the MIN for an entire row or observation.

cynthia
Not applicable
Posts: 0

Re: any simple way to find which one is min in a large set of variables?

cynthia ,
I am trying to find the min for each subject in grp. If one of var is missing, then I will not count, for example, min(aaa)=1, min(bbb=3). Also, given min(aaa)=1, then the function can tell me that it is corresponding to var_1. In R, this is very simple. I want to know if there is any function is SAS can make it easier to code.

Jenny
Posts: 3,852

Re: any simple way to find which one is min in a large set of variables?

[pre]
120 data _null_;
121 array v[3];
122 input grp:\$3. v
• ;
123 min = min(of v
• );
124 j = whichN(min,of v
• );
125 Name = vname(v);
126 put (_all_)(=);
127 cards;

v1=1 v2=2 v3=3 grp=aaa min=1 j=1 Name=v1
v1=. v2=3 v3=4 grp=bbb min=3 j=2 Name=v2
v1=1 v2=0 v3=. grp=ccc min=0 j=2 Name=v2
v1=0 v2=0 v3=0 grp=ddd min=0 j=1 Name=v1
[/pre]
• Discussion stats
• 3 replies
• 110 views
• 0 likes
• 3 in conversation