BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all,

I have a variable x. Now I want to select some of the observations. I want to start with 10units above the minimum and end at minimum plus 30units.
but it doesnt work when I use
where x between min(x+10) and min(x+30);
The min Function take only singlenumbers limitetd by comma.

Have anybody an idea to solve this problem?

Thanks
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You are correct - the WHERE statement (as the same with the IF stmt) will only interrogate the current observation. You need to use PROC SUMMARY/MEANS to generate a file containing the MIN and MAX as new variables, and then one option is to MERGE the resulting file back into your SAS file - then you have the MIN and MAX value range (again, as unique SAS variables created in the MEANS/SUMMARY step) to use in your WHERE statement.

Scott Barry
SBBWorks, Inc.
FredrikE
Rhodochrosite | Level 12
It might not be the beautiest of solutions, but works with smaller datasets:

Proc sql;
select *
from sashelp.class
where age between
(select min(age) + 2 from sashelp.class)
and
(select max(age) - 2 from sashelp.class)
;
quit;

//Fredrik

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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