sql - How to sum all of numeric columns in a table in SAS? -
i have table have variable number of columns based on initial input. there function sum numeric columns of table without specifying name of each column?
right have each column name hard coded in proc sql command.
create table &new_table_name (select sum(case when col1 = &state 1 else 0 end) month_01, sum(case when col2 = &state 1 else 0 end) month_02, sum(case when col3 = &state 1 else 0 end) month_03, sum(case when col4 = &state 1 else 0 end) month_04, sum(case when col5 = &state 1 else 0 end) month_05 );
sample input 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 sample output
name m1 m2 m3 m4 7 16 13 2
you looking proc means
. or summarization proc.
data have; infile datalines missover; input name $ m1 m2 m3 m4; datalines; aa 1 7 7 1 ab 2 4 2 ac 1 1 ad 1 3 1 1 ae 2 1 3 ;;;; run; proc means data=have; output out=want sum=; run;
and class
statement let group state or whatever. where
works fine in proc means
filter.
leaving var
statement off calls numeric variables, or can put in var
statement limit, such as
var m1-m4;
as reeza notes in comments.
Comments
Post a Comment