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_.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.