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
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_.
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_.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.