title: Global macro variables (created with CALL SYMPUTX) won't resolve properly within SAS macro program
body: <p>I'm very new to coding macros in SAS, so I'm mostly looking for a push in the right direction.  </p>
  
  <p>I'm trying to create a big macro program, and within it I'm using <code>CALL SYMPUTX</code> to create several global macro variables that I reference within the macro program.  My code is as follows:</p>
  
  <pre><code>options symbolgen mlogic;
  filename ALBB 'C:\[file path]\AL.csv';
  libname mylibx 'C:\[file path]\ALBB';
  
  %macro baseball(al=mylibx.al, nl=myliby.nl, var1=salary, class1=position, pd=percent_deviation);
  
  data &amp;al;
  infile ALBB dlm=',' dsd firstobs=5 obs=381;
  input team :$20. name :$20. salary :comma12. position :$20.;
  run;
  
  proc print data=&amp;al (firstobs=1 obs=6);
  format &amp;var1 comma12.;
  run;
  
  proc means data=&amp;al noprint;
  var &amp;var1;
  class &amp;class1;
  output out=med_al median=med;
  run;
  
  data median_al;
  set med_al;
  if _TYPE_ = 0 then delete;
  run;
  
  ****Macro Variables in question are below****
  data _NULL_;
  set &amp;al;
      if &amp;class1='Catcher' then call symputx('MedianC',med);
      if &amp;class1='Catcher' then call symputx('FrequencyC',_FREQ_);
      if &amp;class1='First Baseman' then call symputx('MedianFB',med);
      if &amp;class1='First Baseman' then call symputx('FrequencyFB',_FREQ_);
      if &amp;class1='Outfielder' then call symputx('MedianO',med);
      if &amp;class1='Outfielder' then call symputx('FrequencyO',_FREQ_);
      if &amp;class1='Pitcher' then call symputx('MedianP',med);
      if &amp;class1='Pitcher' then call symputx('FrequencyP',_FREQ_);
      if &amp;class1='Second Baseman' then call symputx('MedianSB',med);
      if &amp;class1='Second Baseman' then call symputx('FrequencySB',_FREQ_);
      if &amp;class1='Shortstop' then call symputx('MedianS',med);
      if &amp;class1='Shortstop' then call symputx('FrequencyS',_FREQ_);
      if &amp;class1='Third Baseman' then call symputx('MedianTB',med);
      if &amp;class1='Third Baseman' then call symputx('FrequencyTB',_FREQ_);
  run;
  
  data temp;
  set &amp;al;
      if &amp;class1='Catcher' then &amp;pd=((&amp;var1-&amp;MedianC)/(&amp;MedianC))*100;
      if &amp;class1='First Baseman' then &amp;pd=((&amp;var1-&amp;MedianFB)/(&amp;MedianFB))*100;
      if &amp;class1='Outfielder' then &amp;pd=((&amp;var1-&amp;MedianO)/(&amp;MedianO))*100;
      if &amp;class1='Pitcher' then &amp;pd=((&amp;var1-&amp;MedianP)/(&amp;MedianP))*100;
      if &amp;class1='Second Baseman' then &amp;pd=((&amp;var1-&amp;MedianSB)/(&amp;MedianSB))*100;
      if &amp;class1='Shortstop' then &amp;pd=((&amp;var1-&amp;MedianS)/(&amp;MedianS))*100;
      if &amp;class1='Third Baseman' then &amp;pd=((&amp;var1-&amp;MedianTB)/(&amp;MedianTB))*100;
  run;
  
  proc print data=temp (firstobs=1 obs=10);
  title 'Information about Baseball Players';
  footnote1 %sysfunc(putn(&amp;MedianC, dollar12.)) &amp;FrequencyC;
  footnote2 %sysfunc(putn(&amp;MedianFB, dollar12.)) &amp;FrequencyFB;
  footnote3 %sysfunc(putn(&amp;MedianO, dollar12.)) &amp;FrequencyO;
  footnote4 %sysfunc(putn(&amp;MedianP, dollar12.)) &amp;FrequencyP;
  footnote5 %sysfunc(putn(&amp;MedianSB, dollar12.)) &amp;FrequencySB;
  footnote6 %sysfunc(putn(&amp;MedianS, dollar12.)) &amp;FrequencyS;
  footnote7 %sysfunc(putn(&amp;MedianTB, dollar12.)) &amp;FrequencyTB;
  run;
  
  %mend baseball;
  %baseball()
  </code></pre>
  
  <p>While I'm not sure if I'm doing any of this correctly, it's definitely clear that my <code>'MedianX'</code> and <code>'FrequencyX'</code> macro variables aren't working. They resolve to missing values (whereas outside of the macro program, they resolve correctly). </p>
  
  <p>Could anyone offer some guidance? Thanks very much!</p>