Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Adding/Merging Rows

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-03-2017 08:06 PM
(707 views)

Hi,

In my data, I have multiple rows for one person and I'd like to combine all the rows into one unique row while summing the values. For example:

Where year_id and bat_id are equal, I would like to combine the rows and sum the column values. So for 2015, I would just want one row with values:

82 for G, 232 for AB, and so one. What procedure is best able to do this, or could it be done in the data step?

Thank you,

Justin

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

you could try the proc means

```
data have;
input year_id bat_id$ g ab r h _2b;
cards;
2015 almoa001 51 178 30 47 9
2015 almoa001 31 54 6 11 3
2014 almoa001 32 98 9 26 5
2014 almoa001 27 106 10 21 5
;
proc means data=have nway;
class year_id bat_id;
var g ab r h _2b;
output out=sums sum=/autoname;
run;
```

Thanks,

Jag

Jag

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

you could try the proc means

```
data have;
input year_id bat_id$ g ab r h _2b;
cards;
2015 almoa001 51 178 30 47 9
2015 almoa001 31 54 6 11 3
2014 almoa001 32 98 9 26 5
2014 almoa001 27 106 10 21 5
;
proc means data=have nway;
class year_id bat_id;
var g ab r h _2b;
output out=sums sum=/autoname;
run;
```

Thanks,

Jag

Jag

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

alternatively proc sql

```
proc sql;
create table want as select year_id, bat_id,sum(g) as g, sum(ab) as ab, sum(r) as r, sum(h) as h, sum(_2b) as _2b
from have group by year_id,bat_id;
quit;
```

Thanks,

Jag

Jag

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

⏰

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.** **

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.