Hello, 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
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;
Are the dates actually consecutive? Meaning, there are no gaps in the dates, correct?
Do you have the flag variable already?
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.