Programming the statistical procedures from SAS

counting through a dataset

Reply
New Contributor
Posts: 2

counting through a dataset

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!

PROC Star
Posts: 7,417

Re: counting through a dataset

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;

New Contributor
Posts: 2

Re: counting through a dataset

Thanks!

Super User
Posts: 18,580

Re: counting through a dataset

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;

Ask a Question
Discussion stats
  • 3 replies
  • 240 views
  • 6 likes
  • 3 in conversation