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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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