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
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;
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;
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.
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?
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
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;
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;
Thanks that 's fantastic! It works
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.