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

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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