BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bajtan
Calcite | Level 5

Hello,

I have this problem regarding aggregating a table. For example, my table should look like this

IDbookstoysPCs
1564354184
1454794174
2564373194
254397134
3644361764

except it is a lot bigger. Now, I need to do vertical sum and grouping by ID. The final table should look like this

IDbookstoysPCs
110181148358
2618770328
3644361764

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 7737 views
  • 1 like
  • 2 in conversation