Hi Sas experts,
I have a data set (n= 5000+ observations) with a continuous variable Fx, with values ranging from positive to negative. I want to identify the max value of Fx and select only those observations starting with the max value and all the observations below them. For example if the max value for Fx is on row/ observation 2295, then I want all observations from 2295 to 5000 as a separate data set. If the max value for Fx is on row 1350, then I would like to select row 1350 to row 5000 as a separate data set. Is this possible? I dont want to arrange them in ascending or descending order. From the existing data set, as is, I would like to identify the highest value for Fx column and pick up all observations with highest value for Fx and all rows below the highest value as a separate data set. I have about 270 such data sets. I would really appreciate any help with this?
Have:
Fx
0.25
0.26
0.27
0.33
0.29
0.24
0.19
-0.11
-.28
Want:
Fx
0.33
0.29
0.24
0.19
-0.11
-.28
Thank you so much in advance,
SM
UNTESTED CODE
proc summary data=have;
var fx;
output out=max_value max=max_fx;
run;
data want;
if _n_=1 then set max_value;
set have;
if fx=max_fx then max_fx_flag+1;
if max_fx_flag>0 then output;
drop _type_ _freq_ max_fx_flag max_fx;
run;
UNTESTED CODE
proc summary data=have;
var fx;
output out=max_value max=max_fx;
run;
data want;
if _n_=1 then set max_value;
set have;
if fx=max_fx then max_fx_flag+1;
if max_fx_flag>0 then output;
drop _type_ _freq_ max_fx_flag max_fx;
run;
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.