SAS: Looping over column names -
i have data set following structure:
data account; input index c1 c2 c3 c4 c5 c6 ; datalines; 4 30 20 10 30 40 20 3 50 20 30 50 10 20 ; run; in file, there 150+ columns of "c"-type containing numbers. in each line, sum c: columns index variable , put sum new column. in first line index variable 4, result should sum = c1 + c2 + c3 + c4. in second line, index 3, should sum = c1 + c2 + c3.
how can address columns this? have read them array first?
try this:
data want; set account; array vars c:; sum=0; i=1 index; sum+vars(i); end; drop i; run;
Comments
Post a Comment