collapse - SAS: Collapsing and weighted averages calculations -


i have sas programming problem can't solve on own , i'm thankful imput.

i want collapse data in dataset variable , summarize/average 2 variables based on weights given variable , substract them each other:

example data

number   flag     volume   measure1  measure2 1                 1         2         2         2         b         2         4         5 3                 5         8         20 4         b         10        4         1 5                 9         10        11 6         b         5         2         9 7                 4         11        23 8         b         3         1         8 

now: want volume-weighted average of measure1 , two, calculate measure1-measure2. grouped flags , b:

number flag      volume       volweightmeasure1      volweightmeasure2      finalmeasure 1               19        ((1/19)*2)+((5/19)*8)+...     ...            (volweightmeasure1-volweightmeasure2) 2        b        20        ((2/20)*5)+((10/20)*1)+...    ...            (volweightmeasure1-volweightmeasure2) 

so collapsing volume weighted measures , deducting two. thank input!

best

proc sql;    select flag,sum_volume,sum1/sum_volume volweightmeasure1,sum2/sum_volume volweightmeasure2,           calculated volweightmeasure1-calculated volweightmeasure2 finalmeasure    (select flag,sum(volume) sum_volume, sum(volume*measure1) sum1, sum(volume*measure2) sum2  have group flag); quit; 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -