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

I'm working on a football dataset and I want to create an extra column which represent the sum of points of top 11 players for that team.

The sample data for 2 teams looks something like this. The teams are sorted in descending order of points. So I want to create a 5th variable (sum) which represent the sum of top 11 players for 'AFC Bournemouth' and 'Arsenal FC'

The Position column is totally irrelevant here.

I've attached the complete csv dataset for reference.

 

NameTeamPositionPoints
WilsonAFC BournemouthFWD176.2
FraserAFC BournemouthMID174.7
KingAFC BournemouthFWD105.4
BrooksAFC BournemouthMID104.9
Steve CookAFC BournemouthDEF92.1
AkeAFC BournemouthDEF91
Adam SmithAFC BournemouthDEF66.4
BegovicAFC BournemouthGKP65
FrancisAFC BournemouthDEF59.6
LermaAFC BournemouthMID58.5
GoslingAFC BournemouthMID39.1
StanislasAFC BournemouthMID38.5
DanielsAFC BournemouthDEF36
Lewis CookAFC BournemouthMID31.6
SurmanAFC BournemouthMID21.8
IbeAFC BournemouthMID20.7
RicoAFC BournemouthDEF14.3
DefoeAFC BournemouthFWD6.6
MoussetAFC BournemouthFWD4.3
BorucAFC BournemouthGKP0
HyndmanAFC BournemouthMID0
MingsAFC BournemouthDEF0
PughAFC BournemouthMID0
SimpsonAFC BournemouthDEF0
LacazetteArsenal FCFWD152.3
AubameyangArsenal FCFWD146.3
OzilArsenal FCMID109.8
RamseyArsenal FCMID93.9
XhakaArsenal FCMID91.8
BellerinArsenal FCDEF91.5
MustafiArsenal FCDEF81.4
MkhitaryanArsenal FCMID77.8
MonrealArsenal FCDEF68.5
IwobiArsenal FCMID64.6
TorreiraArsenal FCMID50.5
CechArsenal FCGKP44.4
WelbeckArsenal FCFWD38.5
HoldingArsenal FCDEF36.4
LenoArsenal FCGKP27.8
GuendouziArsenal FCMID27.4
SokratisArsenal FCDEF16.1
KolasinacArsenal FCDEF8.7
LichtsteinerArsenal FCDEF6.5
Maitland-NilesArsenal FCMID3.1
ElnenyArsenal FCMID0
KoscielnyArsenal FCDEF0
MartinezArsenal FCGKP0
MavropanosArsenal FCDEF0
MedleyArsenal FCDEF0
NelsonArsenal FCMID0
NketiahArsenal FCFWD0
Smith-RoweArsenal FCMID0

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So assuming you have everything sorted by team and scoring (seems like you do)

 

data want;
    set have;
    by team;
    if first.team then do; 
       seq=0;
       sum_points=0;
    end;
    seq+1;
    if seq<=11 then sum_points+points;
    if seq>11 then sum_points=.;
run;
    
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

So assuming you have everything sorted by team and scoring (seems like you do)

 

data want;
    set have;
    by team;
    if first.team then do; 
       seq=0;
       sum_points=0;
    end;
    seq+1;
    if seq<=11 then sum_points+points;
    if seq>11 then sum_points=.;
run;
    
--
Paige Miller
lawilap
Fluorite | Level 6
Thanks Paige, that worked, additionally i dropped the name, position, points and seq variable as they were not making sense in final output.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1925 views
  • 1 like
  • 2 in conversation