How to sum variables?

Reply
Contributor
Posts: 62

How to sum variables?

Hi!

I have such type of data:

Cluster  n_t1 n_t2 n_t3 n_t4....

1          4        5      5      1

2          1        1       2      2

3           5       3      2       2

4

5

I need to calculate n=sum(n_t1,n_t2,n_t3,....) for each cluster  while the number of n_t variables changes?

Thanks you!

Violeta

Respected Advisor
Posts: 4,919

Re: How to sum variables?

The following syntax should do it :

data mySums;

set myClusters;

sumN_t = sum(of n_tSmiley Happy;

run;

n_t: means all variable names starting with n_t.

PG

PG
Contributor
Posts: 62

Re: How to sum variables?

Thanks PGStats!

Trusted Advisor
Posts: 1,137

Re: How to sum variables?

by sql

proc sql;

      select *, sum(n_t1,n_t2 ,n_t3, n_t4) as sum from have;

quit;

Thanks,

Jagadish

Thanks,
Jag
Ask a Question
Discussion stats
  • 3 replies
  • 206 views
  • 3 likes
  • 3 in conversation