BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Relle
Calcite | Level 5

Hi ,

I have a charity donations data set that includes unique IDs for individual donors and the amount they have donated at different dates. I have uploaded this into Enterprise guide but what i want to do is to find for each donor Id , the total amount they have donated from their joining date . I want the output to be represented in a table that can be further analysed using Enterprise miner. What are the SAS codes i can use to accomplish this task? Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Similar to what Pritish suggested, but you can limit the variables included:

proc sql;

  create table want as

    select distinct id,sum(donation) as total

      from have

        group by id

  ;

quit;

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

If you just want to add total donations to each record, you could use proc sql.  e.g.:

data have;

  input id donation;

  cards;

1 1

1 2

1 3

2 2

2 4

2 6

3 3

3 .

3 15

;

proc sql;

  create table want as

    select *,sum(donation) as total

      from have

        group by id

  ;

quit;

Relle
Calcite | Level 5

Thank you for the quick reply art297. i forgot to mention i am a green SAS user so not familiar with the codes ...yet. I did try the proc sql query but i noticed the total amount has been created as a new column but each id is still been displayed several times. In the data set a donor id may appear ten times if they have donated ten times on different dates. i want the output to just display the donor id once and they total amount they donated that ten times. I appreciate your suggestion.

art297
Opal | Level 21

I thought that you wanted to keep all of your other data.  Given the above example, what do you want the final file to look like?

Relle
Calcite | Level 5

I want the final file to have for each unique donor id, the total amount of donation . So for example instaed of having same donor id appearing twice in the data set as different records, just have it appear once, but with the total amount they have donated.....

I have other variables within the dataset but they are not relevant so will like to drop them when creating the final file. Just the donor id and the toatal amount donated are required. thanks

art297
Opal | Level 21

Similar to what Pritish suggested, but you can limit the variables included:

proc sql;

  create table want as

    select distinct id,sum(donation) as total

      from have

        group by id

  ;

quit;

Pritish
Quartz | Level 8

Adding to what Art suggested:

data have;

  input id donation;

  cards;

1 1

1 2

1 3

2 2

2 4

2 6

3 3

3 .

3 15

;

proc sql;

  create table want as

    select distinct id,sum(donation) as total

      from have

        group by id

  ;

quit;

Relle
Calcite | Level 5

Thanks that 's fantastic! It works

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 Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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