DATA Step, Macro, Functions and more

calculate with a minimum from the variablelist

Reply
N/A
Posts: 0

calculate with a minimum from the variablelist

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
Super Contributor
Super Contributor
Posts: 3,174

Re: calculate with a minimum from the variablelist

Posted in reply to deleted_user
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.
Regular Contributor
Posts: 191

Re: calculate with a minimum from the variablelist

Posted in reply to deleted_user
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
Ask a Question
Discussion stats
  • 2 replies
  • 133 views
  • 0 likes
  • 3 in conversation