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
SAS Super FREQ
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]
  • sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    Register now!

    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.

    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
    • 3 replies
    • 597 views
    • 0 likes
    • 3 in conversation