0
votes

I have a dataset which has multiple obs per person. I want to have each single record showing the sum of a variable per person ID. However I do not want to group the data into single personal IDs. I hope the example below explains my question

I want to create the column in bold. How to do this? In SAS EG (or SAS if necessary)?

ID...Var1...SUM
X.....10.......30
X.....20.......30
Y.....20.......80
Y.....20.......80
Y.....40.......80
Z.....30.......30

1
It would be more helpful if you could provide an example of the starting dataset, and then an example of the result dataset. - JDB
Are you asking for how to do it with the point and click interface, or with programmatic statements? - Joe
JDB, I agree it could be more clear. Basically the starting dataset is the data in the first two columns, the resulting dataset is the three columns combined. And i prefer to have it solved in the point and click way, but a program can be written as well in SAS EG. - user3389495

1 Answers

0
votes

You can do this using either proc sql or proc means more info:proc means

proc sql

proc sql:

proc sql noprint;

    create table new_table as
    select distinct id, var1, sum(var_to_sum) as summed_var_name
    from old_table
    group by id
    ;
quit;

after rereading your question, using proc means you will need to merge var1 back in, better off using proc sql above.

proc means:

proc means data = old_table sum;
    by id var1;
    var var_to_sum;
    output out = new_table sum;
run;