Hi,
I have a dataset with multiple ID's that I want to reduce to unique ID's through their respective weightings.
For example, the dataset below shows ID, some additional variables required (Var1, Var2) and the weighting (wt).
id | var1 | var2 | wt | AR_Q0 | AR_Q1 | AR_Q2 | AR_Q3 | AR_Q4 | AR_Q5 |
1 | xx | 345 | 0.5 | 10 | 11 | 12 | 13 | 14 | 15 |
1 | xx | 345 | 0.3 | 50 | 51 | 52 | 53 | 54 | 55 |
1 | xx | 345 | 0.2 | 20 | 21 | 22 | 23 | 24 | 25 |
2 | df | 321 | 0.7 | 30 | 31 | 32 | 33 | 34 | 35 |
2 | df | 321 | 0.1 | 40 | 41 | 42 | 43 | 44 | 45 |
2 | df | 321 | 0.2 | 50 | 51 | 52 | 53 | 54 | 55 |
I need to create multiple each AR_Qx value by the weighting and sum up the rows by ID so it looks like this. For example AR_Q5 is calculated as (15*0.5)+(55*0.3)+(25*0.2)=29
id | var1 | var2 | AR_Q0 | AR_Q1 | AR_Q2 | AR_Q3 | AR_Q4 | AR_Q5 |
1 | xx | 345 | 24 | 25 | 26 | 27 | 28 | 29 |
2 | df | 321 | 35 | 36 | 37 | 38 | 39 | 40 |
What is the most efficient way of performing this calculation. At the moment I am doing this in Excel.
Note: Unfortunately I am unable to modify the source dataset as it is part of another process.
Thanks in advance.
proc summary data=have;
class id;
id var1 var2;
var ar_q0-ar_q5;
weight wt;
output out=stats sum=;
run;
proc summary data=have;
class id;
id var1 var2;
var ar_q0-ar_q5;
weight wt;
output out=stats sum=;
run;
Thanks Paige!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: