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

Capture.JPGHello, I need your help.
I have to find all the values that have a total over 1 million, but if the dates are progressive, and there are, for example, 3 consecutive dates with a value over 1 million, I have to select only the date with the highest total.
in the attached example, it should output as output:
dates: 02/01/2000 and 06/01/2000

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @u57961979,


@u57961979 wrote:
No i have only the date and the total

If you don't need the flag as a variable, you can create a format that provides the same information and then use it together with the GROUPFORMAT option of the BY statement in a DATA step:

proc format;
value flag
low -1e6  = '0'
1e6<-high = '1';
run;

data want(drop=d t m);
do until(t>1e6 & last.t);
  set have(rename=(date=d total=t));
  by t groupformat notsorted;
  format t flag.;
  if t>1e6 & t>m then do;
    m=t;
    date=d;
    total=t;
  end;
end;
format date ddmmyy10. total commax16.2;
run; 

 

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Are the dates actually consecutive? Meaning, there are no gaps in the dates, correct?

u57961979
Calcite | Level 5
yes the date are all consecutive
PeterClemmensen
Tourmaline | Level 20

Do you have the flag variable already?

u57961979
Calcite | Level 5
No i have only the date and the total
FreelanceReinh
Jade | Level 19

Hello @u57961979,


@u57961979 wrote:
No i have only the date and the total

If you don't need the flag as a variable, you can create a format that provides the same information and then use it together with the GROUPFORMAT option of the BY statement in a DATA step:

proc format;
value flag
low -1e6  = '0'
1e6<-high = '1';
run;

data want(drop=d t m);
do until(t>1e6 & last.t);
  set have(rename=(date=d total=t));
  by t groupformat notsorted;
  format t flag.;
  if t>1e6 & t>m then do;
    m=t;
    date=d;
    total=t;
  end;
end;
format date ddmmyy10. total commax16.2;
run; 

 

u57961979
Calcite | Level 5
thank you so much

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 969 views
  • 1 like
  • 3 in conversation