BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sms1891
Quartz | Level 8

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 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 272 views
  • 0 likes
  • 2 in conversation