BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?
3 REPLIES 3
Cynthia_sas
Diamond | Level 26
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
deleted_user
Not applicable
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
data_null__
Jade | Level 19
[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]
  • hackathon24-white-horiz.png

    The 2025 SAS Hackathon Kicks Off on June 11!

    Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

    YouTube LinkedIn

    What is Bayesian Analysis?

    Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

    Find more tutorials on the SAS Users YouTube channel.

    SAS Training: Just a Click Away

     Ready to level-up your skills? Choose your own adventure.

    Browse our catalog!

    Discussion stats
    • 3 replies
    • 1131 views
    • 0 likes
    • 3 in conversation