In your earlier thread, code was provided to compute the cumulative percent by group. So any observation where the cumulative percent is <=95% would be flagged.
First, you should show exactly what the desired output looks like.
Second, 95% of what? Percentages involve numerators and denominators. You show 5 values in our A group. That means each value is 20% of the number of values. Or is the numeric value a count of some sort? So do you mean 95% of the total count?
If your data is supposed to be counts how did you make them? That could simplify you issue.
Consider the results here that adds a cumulative percent when counting.
proc sort data=sashelp.class out=work.class; by sex; run; proc freq data=work.class order=freq; by sex; ods output onewayfreqs=work.count; tables age ; run;
you need to decide and describe what the result looks like when there is not a "nice" 95% boundary.
It is very likely that the next to last in a sorted group is considerably less than 95 and jumps from maybe 80% to 100.
And what about ties of the value?
In your earlier thread, code was provided to compute the cumulative percent by group. So any observation where the cumulative percent is <=95% would be flagged.
So I used SAShelp.CARS. Proc means can calculate percentiles for you. You can then merge those percentiles back with the original dataset selecting records less than or greater than the percentile for the group.
Here I'm finding the MSRPs less than the 75th percentile for each Make.
PROC MEANS DATA=SASHELP.CARS
NOPRINT CHARTYPE QMETHOD=OS NONOBS Q3 ;
VAR MSRP;
BY Make;
OUTPUT OUT=Percentiles
Q3()=
/ AUTONAME AUTOLABEL INHERIT
;
RUN;
PROC SQL;
CREATE TABLE wantish AS
SELECT CARS.Make,
CARS.Model,
CARS.MSRP
FROM SAShelp.CARS
INNER JOIN
Percentiles p
ON (CARS.Make = p.Make)
WHERE CARS.MSRP < p.MSRP_Q3;
QUIT;
With a data step:
data want;
do until(last.group);
set have; by group;
totValue = sum(totValue, value);
end;
do until(last.group);
set have; by group;
cumValue = sum(cumValue, value);
flag = (totValue - cumValue) >= 0.05 * totValue;
output;
end;
drop totValue cumValue;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.