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

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!

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