简体   繁体   中英

How to select the largest variable in a dataset and assign it to a macro in sas

Salutations, I need to take the largest value in a column. So I can turn it into a variable and use it in another query. something like.

%let maxyear = MAX(STay_yr)

help!

You can use proc SQL and into:

proc sql;
  select max(STay_yr) into :maxyear
  from some_dataset;
quit;

And another david25272 's variant:

data _null_;
   set have end = last;
   retain max_STay_yr;
   if STay_yr > max_STay_yr then max_STay_yr = STay_yr;
   if last then call symput("maxyear",max_STay_yr);
run;

Variable maxyear will have the maximum value.

You can take the values from it further as &maxyear .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM