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

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!

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