BookmarkSubscribeRSS Feed
daclon
Calcite | Level 5

Hello,

I am new to SAS and my question might seem stupid to SAS experts. All I need is to write a program that does the following: I have a huge data set (several millions values) of people who payed for something. The same name may appear multiple times in the list with different amounts payed. The program should count how much each person spent in total and to output the name of the person who spent the highest amount.

thanks for your help!

3 REPLIES 3
art297
Opal | Level 21

You could use proc sql.  e.g.:

data have;

  input id spent;

  cards;

1 1

1 1

1 2

2 3

2 4

2 5

;

proc sql;

  select distinct id,total_spent

    from (select *,sum(spent) as total_spent

           from have

             group by id)

      having total_spent eq max(total_spent)

  ;

quit;

daclon
Calcite | Level 5

Thanks!

Reeza
Super User

What does your data look like?

You can check proc freq with the weights option or proc summary to summarize your data.

e.g.

proc freq data=have order=freq no print;

table users/out=summary1;

weight amount_payed;

run;

OR

proc means data=have noprint;

class users;

var amount_payed;

output out=summary2 sum(amount_payed)=total_payed;

run;

proc sort data=summary2;

by descending total_payed;

run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1799 views
  • 6 likes
  • 3 in conversation