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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1213 views
  • 6 likes
  • 3 in conversation