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.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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