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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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