BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AK100
Pyrite | Level 9

Hello all,


I'am quite new to SAS EG and I want to get the following: I want to select all the measurements who have the highest percentage (from high to low per month AND section) till I reach a cumulative total percentage of minimal 75%. .

 

So (see screenshot) from the month July and section 2632CT I want to select just the percentage 53% + 28% in a cumulative column. For the month July and section 2646BT I want to select just 49% and 26% in cumulative etc. So I just want to select the highest percentages in a cumulative form until I reach a minimal of 75%. The count has to start from 0 again at the beginning of every new section (so actually 2x per month)

 

AK100_0-1585575375169.png

 

I hope its all clear, I appreciate your help.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Slight problem with the code suggested by @Kurt_Bremser . I'd use:

proc sort data=have out=need;
  by maand1 sectie descending percentage;
run;

data want;
  set need;
  by maand1 sectie;
  if first.sectie then sum_perc = 0;
  if sum_perc lt .75 then do;
    sum_perc+percentage;
    output;
  end;
  drop sum_perc;
run;

Art, CEO, AnalystFinder.com

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

Sort by month, section and descending percentage;

Then do

data want;
set have;
by maand1 sectie;
if sum_perc le .75 then output;
if first.section
then sum_perc = percentage;
else sum_perc + percentage; /* causes automatic retain */
drop sum_perc;
run;
art297
Opal | Level 21

Slight problem with the code suggested by @Kurt_Bremser . I'd use:

proc sort data=have out=need;
  by maand1 sectie descending percentage;
run;

data want;
  set need;
  by maand1 sectie;
  if first.sectie then sum_perc = 0;
  if sum_perc lt .75 then do;
    sum_perc+percentage;
    output;
  end;
  drop sum_perc;
run;

Art, CEO, AnalystFinder.com

AK100
Pyrite | Level 9
That was a good one @art297.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1389 views
  • 1 like
  • 3 in conversation