title: SAS differences in outcome between sql and proc means
body: <p>I want to have a weighted average of some variable in a macro variable. My var is <em>zindi&amp;aa</em> and my weight is <em>wprm&amp;aa</em></p>
  
  <p>I am trying to make sense of two ways of doing it : </p>
  
  <p><strong>one with a proc sql</strong></p>
  
  <pre><code>proc sql noprint;
      select mean(zindi&amp;aa. * wprm&amp;aa.)/sum(wprm&amp;aa.) into :Mean_zindi_aa
      from Panel(where=(annee&amp;ap.&lt;="&amp;nais18" ));
  quit;
  </code></pre>
  
  <p>it yields me an average of <strong>0.77</strong></p>
  
  <p><strong>one with proc means</strong></p>
  
  <pre><code>proc means data=Panel(where=(annee&amp;ap.&lt;="&amp;nais18" )); 
      var zindi&amp;ap. ;
      weight wprm&amp;ap ;
      output out=mean_zindi&amp;ap mean=moy&amp;ap;
  run;
  </code></pre>
  
  <p>and then a data _null_ part</p>
  
  <p>which yields an average of around <strong>20200</strong> that seems to be the correct one</p>
  
  <p>so my question is </p>
  
  <ul>
  <li>what  I am missing with the proc sql so that it does give an absurd result ? </li>
  <li>is there a better way to obtain my macro variable <strong>&amp;mean_zindi_aa</strong></li>
  </ul>