<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic What is an efficient way to create multiple excel spreadsheets with different tabs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666651#M199498</link>
    <description>&lt;P&gt;I have 6 tables that contains different information (price, region, sales, manger, etc) for all inventory items.&lt;/P&gt;&lt;P&gt;I need to create excel spreadsheet for each inventory item. This excel spreadsheet would have 6 separate tabs to show each item's info from the corresponding tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what I am doing (also see codes below)&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Assign XLSX libname to create an excel file for each Inventory item&lt;/LI&gt;&lt;LI&gt;Use Macro A and B to create spreadsheet with 6 separate tabs for inventory item z3597 and J64x9, respectively&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;My question is since I have around 25 inventory items (and this number may go up or down each weekly), I would need to assign 25 XLSX libname and run the same macro for 25 times for each inventory number.&lt;/P&gt;&lt;P&gt;What is a more efficient way or better way to accomplish this task? Thanks for everyone's advices.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LIBNAME A XLSX '/sharedspace/inventory/users/sammy/file_one.XLSX';&lt;BR /&gt;LIBNAME B XLSX '/sharedspace/inventory/users/sammy/file_two.XLSX';&lt;BR /&gt;LIBNAME Inv '/sharedspace/inventory/weekly/Inv';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO A(SHEET_NAME, TABLE);&lt;BR /&gt;DATA A.&amp;amp;SHEET_NAME;&lt;BR /&gt;SET Inv.&amp;amp;TABLE (WHERE=(Inventory_num EQ "Z35q7"));&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND;&lt;/P&gt;&lt;P&gt;%A(INVENTORY_PRICE,INVENTORY_PRICE);&lt;BR /&gt;%A(INVENTORY_REGION,INVENTORY_REGION);&lt;BR /&gt;%A(INVENTORY_SALES,INVENTORY_SALES);&lt;BR /&gt;%A(INVENTORY_MANAGER,INVENTORY_MANAGER);&lt;BR /&gt;%A (INVENTORY_PRODUCT, INVENTORY_PRODUCT);&lt;BR /&gt;%A (INVENTORY_TYPE,INVENTORY_TYPE );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO B(SHEET_NAME, TABLE);&lt;BR /&gt;DATA B.&amp;amp;SHEET_NAME;&lt;BR /&gt;SET Inv.&amp;amp;TABLE (WHERE=(Inventory_num EQ "J64x9"));&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND;&lt;BR /&gt;%B(INVENTORY_PRICE,INVENTORY_PRICE);&lt;BR /&gt;%B(INVENTORY_REGION,INVENTORY_REGION);&lt;BR /&gt;%B(INVENTORY_SALES,INVENTORY_SALES);&lt;BR /&gt;%B(INVENTORY_MANAGER,INVENTORY_MANAGER);&lt;BR /&gt;%B (INVENTORY_PRODUCT, INVENTORY_PRODUCT);&lt;BR /&gt;%B (INVENTORY_TYPE,INVENTORY_TYPE );&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jul 2020 17:38:53 GMT</pubDate>
    <dc:creator>LL5</dc:creator>
    <dc:date>2020-07-02T17:38:53Z</dc:date>
    <item>
      <title>What is an efficient way to create multiple excel spreadsheets with different tabs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666651#M199498</link>
      <description>&lt;P&gt;I have 6 tables that contains different information (price, region, sales, manger, etc) for all inventory items.&lt;/P&gt;&lt;P&gt;I need to create excel spreadsheet for each inventory item. This excel spreadsheet would have 6 separate tabs to show each item's info from the corresponding tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what I am doing (also see codes below)&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Assign XLSX libname to create an excel file for each Inventory item&lt;/LI&gt;&lt;LI&gt;Use Macro A and B to create spreadsheet with 6 separate tabs for inventory item z3597 and J64x9, respectively&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;My question is since I have around 25 inventory items (and this number may go up or down each weekly), I would need to assign 25 XLSX libname and run the same macro for 25 times for each inventory number.&lt;/P&gt;&lt;P&gt;What is a more efficient way or better way to accomplish this task? Thanks for everyone's advices.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LIBNAME A XLSX '/sharedspace/inventory/users/sammy/file_one.XLSX';&lt;BR /&gt;LIBNAME B XLSX '/sharedspace/inventory/users/sammy/file_two.XLSX';&lt;BR /&gt;LIBNAME Inv '/sharedspace/inventory/weekly/Inv';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO A(SHEET_NAME, TABLE);&lt;BR /&gt;DATA A.&amp;amp;SHEET_NAME;&lt;BR /&gt;SET Inv.&amp;amp;TABLE (WHERE=(Inventory_num EQ "Z35q7"));&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND;&lt;/P&gt;&lt;P&gt;%A(INVENTORY_PRICE,INVENTORY_PRICE);&lt;BR /&gt;%A(INVENTORY_REGION,INVENTORY_REGION);&lt;BR /&gt;%A(INVENTORY_SALES,INVENTORY_SALES);&lt;BR /&gt;%A(INVENTORY_MANAGER,INVENTORY_MANAGER);&lt;BR /&gt;%A (INVENTORY_PRODUCT, INVENTORY_PRODUCT);&lt;BR /&gt;%A (INVENTORY_TYPE,INVENTORY_TYPE );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO B(SHEET_NAME, TABLE);&lt;BR /&gt;DATA B.&amp;amp;SHEET_NAME;&lt;BR /&gt;SET Inv.&amp;amp;TABLE (WHERE=(Inventory_num EQ "J64x9"));&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND;&lt;BR /&gt;%B(INVENTORY_PRICE,INVENTORY_PRICE);&lt;BR /&gt;%B(INVENTORY_REGION,INVENTORY_REGION);&lt;BR /&gt;%B(INVENTORY_SALES,INVENTORY_SALES);&lt;BR /&gt;%B(INVENTORY_MANAGER,INVENTORY_MANAGER);&lt;BR /&gt;%B (INVENTORY_PRODUCT, INVENTORY_PRODUCT);&lt;BR /&gt;%B (INVENTORY_TYPE,INVENTORY_TYPE );&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 17:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666651#M199498</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-07-02T17:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to create multiple excel spreadsheets with different tabs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666663#M199506</link>
      <description>&lt;P&gt;CALL EXECUTE()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use call execute to dynamically call your macro for a list of variables/criteria that you can generate.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 18:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666663#M199506</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-02T18:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to create multiple excel spreadsheets with different tabs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666704#M199529</link>
      <description>&lt;P&gt;Thanks Reeza, can you give me a quick example?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 21:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666704#M199529</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-07-02T21:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to create multiple excel spreadsheets with different tabs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666715#M199535</link>
      <description>&lt;P&gt;Call Execute specifically:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/beb97b1c6d4517dde3b2" target="_blank"&gt;https://gist.github.com/statgeek/beb97b1c6d4517dde3b2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 21:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666715#M199535</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-02T21:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to create multiple excel spreadsheets with different tabs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666766#M199563</link>
      <description>&lt;P&gt;Rather than using CALL EXECUTE, I normally write a program to a temporary file and %INCLUDE that. Mostly because the development is easier:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You can see all the code you have generated before executing&lt;/LI&gt;
&lt;LI&gt;You can test a few of the generated steps before committing the whole batch&lt;/LI&gt;
&lt;LI&gt;When you are done testing, you can add the %INCLUDE statement to your program&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming that you have the inventory items in a table called INVENTORY, you can do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename tempsas temp;

data _null_;
  set inventory;
  file tempsas;  
  put
     '%A(' item ',' item ');' /
     '%B(' item ',' item ');' /
     ;
run;

%include tempsas /source2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as I said, you may want to take a look at the generated code and test a couple of statements before adding the %INCLUDE statement to your program.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 09:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666766#M199563</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-07-03T09:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to create multiple excel spreadsheets with different tabs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666845#M199589</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Rather than using CALL EXECUTE, I normally write a program to a temporary file and %INCLUDE that. Mostly because the development is easier:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You can see all the code you have generated before executing&lt;/LI&gt;
&lt;/UL&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I create my strings to pass to call execute in a variable STR that I can check before executing as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;UL&gt;
&lt;LI&gt;You can test a few of the generated steps before committing the whole batch&lt;/LI&gt;
&lt;/UL&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can do that by limiting the obs in the input data set using the OBS= option to test it for a small portion of your code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;UL&gt;
&lt;LI&gt;When you are done testing, you can add the %INCLUDE statement to your program&lt;/LI&gt;
&lt;/UL&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And then I uncomment the CALL EXECUTE() sections so that they run all at once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think both approaches are almost equivalent today. One plus to the %INCLUDE method though is that you do get a record of what was submitted that's easier to debug than going through the log of a CALL EXECUTE() generated program.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 15:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666845#M199589</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-03T15:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to create multiple excel spreadsheets with different tabs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666854#M199593</link>
      <description>&lt;P&gt;The big advantages of writing the code to a file instead of CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;1) Macro timing.&amp;nbsp; When using CALL EXECUTE to run macros that do code generation based on macro variables created in the macro you have to wrap the macro call in %NRSTR() to avoid timing issues.&lt;/P&gt;
&lt;P&gt;2) The power of the PUT statement.&amp;nbsp; You can use formats, VAR=.&lt;/P&gt;
&lt;P&gt;3) The code can be formatted for human readability.&lt;/P&gt;
&lt;P&gt;4) Same logic can then been used to generate code files that used in independent jobs.&amp;nbsp; For example: Run your code generation step when the metadata changes and then schedule the generated code to run whenever the data changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only advantage of CALL EXECUTE is that it is fewer steps. So good for quick code generation that is not too complex.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 15:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-an-efficient-way-to-create-multiple-excel-spreadsheets/m-p/666854#M199593</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-03T15:50:37Z</dc:date>
    </item>
  </channel>
</rss>

