I have a table that will have a variable number of columns based on my initial input. Is there a function to sum all the numeric columns of this table without specifying the name of each column?
Right now I have each column name hard coded in a proc sql command.
CREATE TABLE &new_table_name AS
(SELECT SUM(CASE WHEN col1 = &state THEN 1 ELSE 0 END) AS month_01,
SUM(CASE WHEN col2 = &state THEN 1 ELSE 0 END) AS month_02,
SUM(CASE WHEN col3 = &state THEN 1 ELSE 0 END) AS month_03,
SUM(CASE WHEN col4 = &state THEN 1 ELSE 0 END) AS month_04,
SUM(CASE WHEN col5 = &state THEN 1 ELSE 0 END) AS month_05
);
Sample input would be like this:
name m1 m2 m3 m4
aa 1 7 7 1
ab 2 4 2
ac 1 1
ad 1 3 1 1
ae 2 1 3
Then the sample output would be
name m1 m2 m3 m4
7 16 13 2