BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

Hi,

I want to find record that: v1< min (v2,v3,v4.... vn).

Is there way rather than listing all v?

Thanks 

HHC

data a; 
input id v1 v2 v3 v4 v5;
datalines;
1 4 5 6 7 8
2 5 9 10 85 3
3 99 1 2 3 4
;run;

data b; set a;
if v1< min(v2-v5); *SAS take it as minus;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @hhchenfx,

 

For a numbered range list or a name range list (see documentation of SAS Variable Lists) you can use the OF operator without an array. Both of these are applicable to your example:

 

Numbered range list:

if v1 < min(of v2-v5);

Name range list:

if v1 < min(of v2--v5);

The OF operator signals that the hyphens between "v2" and "v5" are not minus signs.

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

Define an array containing V2-V5 (using v2-v5 expession), then find the minimum of that array, using the of arrayname{*} expression:  

 

data a; 
input id v1 v2 v3 v4 v5;
datalines;
1 4 5 6 7 8
2 5 9 10 85 3
3 99 1 2 3 4
;run;

data b; set a;
  array _v2_thru_5 {*} v2-v5;
  if v1< min(of _v2_thru_5{*}); 
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
FreelanceReinh
Jade | Level 19

Hi @hhchenfx,

 

For a numbered range list or a name range list (see documentation of SAS Variable Lists) you can use the OF operator without an array. Both of these are applicable to your example:

 

Numbered range list:

if v1 < min(of v2-v5);

Name range list:

if v1 < min(of v2--v5);

The OF operator signals that the hyphens between "v2" and "v5" are not minus signs.

Kurt_Bremser
Super User

If the methods already proposed can work depends on the real names of your variables.

If you have such nicely numbered names, then the "of v2-v5" will work. But if you have names like a b c d e f (no numeric suffix, or no complete sequence), you will need the "of b--f" construct, but this depends on the physical sequence of variables within an observation, and that can change in numerous ways without you even noticing it (no WARNING, ERROR or NOTE in the log).

For the latter, I would go with a preceding step that extracts the necessary names from DICTIONARY.COLUMNS into a macro variable for use in the MIN function.

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2083 views
  • 6 likes
  • 4 in conversation