Posts

Showing posts with the label sas

SAS: sum over subset of a table column (multiple times)

SAS: sum over subset of a table column (multiple times) (I'm new to SAS, and I struggle with how involved it is to do stuff column-wise which would be quite easy in a "normal" language. Please bear with me if this is extremely basic.) I have a table with values type , a1-a10 and b1-b10 , and I would like to find (for each N ) the sum of bN for those rows where aN is positive. I can do it one variable at a time, e.g. with something like this: proc sql; create table work.test1 as select type, b1 from work.table where (a1 >0); run; and then sum over all those tables and then merge them, but that's going to be a lot of code and a bit of a faff. Is there a nice and compact way to do this? Edit: The output I'd like is a table with values type , sum1-sum10 , where sumN is the sum described above. Sample data: type | a1 | a2 | ... | b1 | b2 | ... ------------------------------------ cat 10 14 ... 1 2 ... cat -5 3 ... 1 1 ....