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
- /
- SAS Procedures
- /
- any simple way to find which one is min in a large...

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

10-27-2010 05:23 PM

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?

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

10-27-2010 06:19 PM

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

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

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

10-28-2010 08:44 AM

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

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

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

10-28-2010 08:55 AM

[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]

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]