Help using Base SAS procedures

PROC codes for tables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

PROC codes for tables

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


Accepted Solutions
Solution
‎02-08-2012 11:04 AM
PROC Star
Posts: 7,468

PROC codes for tables

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


All Replies
PROC Star
Posts: 7,468

PROC codes for tables

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;

Occasional Contributor
Posts: 8

PROC codes for tables

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.

PROC Star
Posts: 7,468

PROC codes for tables

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?

Occasional Contributor
Posts: 8

PROC codes for tables

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

Solution
‎02-08-2012 11:04 AM
PROC Star
Posts: 7,468

PROC codes for tables

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;

Contributor
Posts: 65

Re: PROC codes for tables

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;

Occasional Contributor
Posts: 8

PROC codes for tables

Thanks that 's fantastic! It works

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 156 views
  • 6 likes
  • 3 in conversation