title: How to export SAS dataset to XLSX, by category, using macro variable?
body: <p>I have a large data set that has approximately 100 names of managers. Now, I need to export the data by manager name so that I have a single dataset for each manager. I am able to use a macro to create a separate dataset for each manager (essentially, a category) using the code:</p>
  
  <pre><code>%macro break(byval);                                                                                                                                  
     data &amp;byval;                                                             
        set final(where=(Project_Manager_Name="&amp;byval"));                              
     run;                                                                                                                                                 
  %mend;                                                                      
  
  data _null_;                                                                
    set final;                                                               
    by Project_Manager_Name;                                                                  
    if first.Project_Manager_Name then 
      call execute(%nrstr('%break('||trim(Project_Manager_Name)||')'));            
   run;
  </code></pre>
  
  <p>This is where I get stuck. I just need .xlsx files of each and include the name of the manager at the end of each file name, like:</p>
  
  <pre><code>proc export
      data = final
      dbms = xlsx
      outfile = "&amp;OUTPUT.\Final_Report_ManagerName.xlsx"
      replace;
  run;
  </code></pre>
  
  <p>I assume I put the <code>&amp;byval</code> macro variable somewhere in the outfile name, but I'm still getting errors that it's not being reference. Any insight?</p>