- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have this problem regarding aggregating a table. For example, my table should look like this
ID | books | toys | PCs |
1 | 564 | 354 | 184 |
1 | 454 | 794 | 174 |
2 | 564 | 373 | 194 |
2 | 54 | 397 | 134 |
3 | 644 | 361 | 764 |
except it is a lot bigger. Now, I need to do vertical sum and grouping by ID. The final table should look like this
ID | books | toys | PCs |
1 | 1018 | 1148 | 358 |
2 | 618 | 770 | 328 |
3 | 644 | 361 | 764 |
This alone would be easy, but now comes the twist. I have many columns and they change quite often, so I would love some solution which uses a vector of column names or an option to sum all the columns irrespective of the column names. Is there such an option?
Thanks,
Bajtan
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc summary data=have nway;
class id;
var _numeric_;
output out=want sum=;
run;
This assumes ID is character. If you don't want ALL numeric variables to be summed, you can write queries with SQL to extract variable names of interest, put those variable names in a macro variable and then use that instead of _NUMERIC_.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc summary data=have nway;
class id;
var _numeric_;
output out=want sum=;
run;
This assumes ID is character. If you don't want ALL numeric variables to be summed, you can write queries with SQL to extract variable names of interest, put those variable names in a macro variable and then use that instead of _NUMERIC_.
Paige Miller