I need find dynamic minimum value depend on _n_ , some like below,
Column K is the field I want, but the min range is changed by N. I did have some marco set up but it did not work since it did not take _N_ as numeric
%LET T=_N_;
want =MIN(OF X(&T)-X(&T+3));
anyone can help? many Appreciate here!
Hello @yj111 and welcome to the SAS Support Communities!
Do you have only six variables x1-x6 and six observations?
Then use an array, no macro variables needed:
data want;
set have;
array a[8] x1-x6 x6 x6;
if n(a[_n_],a[_n_+1],a[_n_+2]) then m=min(a[_n_],a[_n_+1],a[_n_+2]);
run;
If you don't have missing values, you can omit the IF condition.
It works perfectly!!
Thank you!
Hello @yj111 , you need to mark the reply from @FreelanceReinh as correct and not your reply that says it works perfectly as the correct answer.
No macros needed, nor would they be a good idea here. This is a place where an ARRAY works perfectly.
data want;
set have;
array x x1-x6;
if _n_>1 and _n_<6 then min_for_row=min(x(_n_+1),x(_n_));
else if _n_=1 then min_for_row=min(of x1-x3);
else if _n_=6 then min_for_row=x6;
run;
@yj111 wrote:
thank you Paige!
Repeating my earlier request:
"Hello @yj111 , you need to mark the reply from @FreelanceReinhard as correct and not your reply that says it works perfectly as the correct answer."
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!
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.