suppose to have the following:
data have; input ID :$20. Label :$20. Hours :$20. Days :$20.; cards; 0001 w 3144 3 0001 w 23 54 0001 p 12 1 0002 m 456 34 0002 w 2 1 0002 s 231 45 0002 w 98 23 0003 w 12 6 0003 w 98 76 ;
Is there a way to, for each ID, sum the Hours, so get the total and then split it by the days but only when the label is == w? If the label is not w put a missing.
Desired output:
data have; input ID :$20. Label :$20. Hours :$20. Days :$20.; cards; 0001 w 167.3158 3 0001 w 3011.684 54 0001 p . 1 0002 m . 34 0002 w 32.79167 1 0002 s . 45 0002 w 754.2084 23 0003 w 8.048778 6 0003 w 101.9512 76 ;
In other words: for 0001 in the desired output example I added: 3144+23+12 = 3179, the 54+3=57 that are the days where the label is "w" then I divided 3179 by 57 and multiplied the result for 3 and 54 but not for 1 respectively.
Thank you in advance