<?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 Re: Proc Export in Macro Loop in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697918#M37483</link>
    <description>Good catch!</description>
    <pubDate>Tue, 10 Nov 2020 16:04:36 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-11-10T16:04:36Z</dc:date>
    <item>
      <title>Proc Export in Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697911#M37481</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro to create several tables. I use a Do loop to create these tables using proc sql. I need to add a proc export to the loop, such that every time it creates a table, it exports it in excel to a path:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select distinct month,count(distinct month) into :names1-,:c
from X;
quit;

%macro t;
proc sql;
%do i =1 %to &amp;amp;c;
 create table &amp;amp;&amp;amp;names&amp;amp;i as
 select *
 from X
 where strip(month)="&amp;amp;&amp;amp;names&amp;amp;i";
quit;

 proc export 
  data=&amp;amp;&amp;amp;names&amp;amp;i
  dbms=xlsx 
  outfile="\\...\&amp;amp;&amp;amp;names&amp;amp;i..xlsx" 
  replace;
run;
%end;

%mend t;
options mprint;
%t&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, proc export does not work after proc sql in macro loop. Could you please help me how to use proc export here to export each table that this loop generates? Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 15:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697911#M37481</guid>
      <dc:creator>sun538</dc:creator>
      <dc:date>2020-11-10T15:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Export in Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697914#M37482</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Hi, &lt;SPAN&gt;sun538.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Try to put &lt;EM&gt;proc sql;&lt;/EM&gt; sentence inside do loop.

proc sql ;
select distinct month,count(distinct month) into :names1-,:c
from X;
quit;

%macro t;
%do i =1 %to &amp;amp;c;
proc sql;
 create table &amp;amp;&amp;amp;names&amp;amp;i as
 select *
 from X
 where strip(month)="&amp;amp;&amp;amp;names&amp;amp;i";
quit;

 proc export 
  data=&amp;amp;&amp;amp;names&amp;amp;i
  dbms=xlsx 
  outfile="\\...\&amp;amp;&amp;amp;names&amp;amp;i..xlsx" 
  replace;
run;
%end;

%mend t;
options mprint;
%t&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 15:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697914#M37482</guid>
      <dc:creator>jarapoch</dc:creator>
      <dc:date>2020-11-10T15:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Export in Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697918#M37483</link>
      <description>Good catch!</description>
      <pubDate>Tue, 10 Nov 2020 16:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697918#M37483</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-10T16:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Export in Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697920#M37484</link>
      <description>Thanks for your catch. Appreciate it!</description>
      <pubDate>Tue, 10 Nov 2020 16:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697920#M37484</guid>
      <dc:creator>sun538</dc:creator>
      <dc:date>2020-11-10T16:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Export in Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697921#M37485</link>
      <description>&lt;P&gt;Thank you, Reeza!!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 16:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697921#M37485</guid>
      <dc:creator>jarapoch</dc:creator>
      <dc:date>2020-11-10T16:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Export in Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697922#M37486</link>
      <description>&lt;P&gt;In the future, for problems like this, show us the log, along with the original code.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 16:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697922#M37486</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-10T16:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Export in Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697926#M37487</link>
      <description>&lt;P&gt;Do you really need the individual datasets? Or just the sheets in the XLSX file?&amp;nbsp; If so there is no need to for the SQL step.&lt;/P&gt;
&lt;P&gt;Plus then you can use the REAL values of MONTH when creating the macro variables so you don't need the STRIP() function in the WHERE clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro t;
proc sql ;
  select distinct quote(trim(month)) into :names1- from X;
%let c=&amp;amp;sqlobs;
quit;

%do i =1 %to &amp;amp;c;
proc export data=X(where=(month=&amp;amp;&amp;amp;names&amp;amp;i))
  dbms=xlsx replace
  outfile="\\...\&amp;amp;&amp;amp;names&amp;amp;i..xlsx" 
;
run;
%end;
%mend t;

options mprint;
%t&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 16:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Export-in-Macro-Loop/m-p/697926#M37487</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-10T16:31:27Z</dc:date>
    </item>
  </channel>
</rss>

