BookmarkSubscribeRSS Feed
zoeshrugged
Calcite | Level 5

Hi, I have two datasets and I have the points earned and the points given up for a list of sports teams. I want to find out the highest margin between points earned-points given up.

For example, if it was like this:

TeamPoints EarnedPoints Given up
Lions2010
Ravens3021
Broncos305

Then we would know the Broncos had the highest margin. How do I write a formula for this?

Any assistance would be greatly appreciated!

2 REPLIES 2
Haikuo
Onyx | Level 15

There will be many solutions, here is one of them:

data have;

input team:$8. points_earned points_give;

cards;

Lions 20 10

Ravens 30 21

Broncos 30 5

;

proc sql;

     select * from have having abs(points_earned-points_give)=max(abs(points_earned-points_give));

quit;

art297
Opal | Level 21

I would modify 's formula, as given the following scenario, I doubt that you would want the Rams to come out on top:

data have;

input team:$8. points_earned points_give;

cards;

Lions 20 10

Ravens 30 21

Broncos 30 5

Rams 5 31

;

proc sql;

  select *

    from have

      having points_earned-points_give=max(points_earned-points_give)

  ;

quit;

Further, you may want to consider comparing deltas rather than differences. If so,:

proc sql;

  select * ,points_earned/points_give-1

    from have

      having points_earned/points_give-1=max(points_earned/points_give-1)

  ;

quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 2 replies
  • 418 views
  • 0 likes
  • 3 in conversation