<?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 SAS Proc Export statement - Export multiple subset files via loop in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452691#M69837</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to export multiple excel files based on a user inputted macro value Job.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Job will look like this (user input)&lt;/P&gt;&lt;P&gt;129692,135534, 135512&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, if the user inputs&amp;nbsp;three&amp;nbsp;jobs,&amp;nbsp;three files will be created:&lt;/P&gt;&lt;P&gt;OUTPUT_129692&lt;/P&gt;&lt;P&gt;OUTPUT_135534&lt;/P&gt;&lt;P&gt;OUTPUT_&lt;SPAN&gt;135512&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run the code below -- I cannot seem to get the export statement to subset the data successfully and output each individual file&lt;/P&gt;&lt;P&gt;The error returns %SCAN has too many arguments:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
%local i nextjob;
%do i=1 %to %sysfunc(countw("&amp;amp;job.",","));
%let nextjob = %scan(&amp;amp;job., &amp;amp;i);

 proc export data = temp.IDs_SUM (where=(jobid = "&amp;amp;nextjob."))
		outfile="/USERFOLDER/OUTPUT_&amp;amp;nextjob..xlsx"
		DBMS=XLSX REPLACE;
	run;

%end;
%mend loop;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any tips on what I am doing wrong?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 09 Apr 2018 22:55:34 GMT</pubDate>
    <dc:creator>Terho</dc:creator>
    <dc:date>2018-04-09T22:55:34Z</dc:date>
    <item>
      <title>SAS Proc Export statement - Export multiple subset files via loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452691#M69837</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to export multiple excel files based on a user inputted macro value Job.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Job will look like this (user input)&lt;/P&gt;&lt;P&gt;129692,135534, 135512&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, if the user inputs&amp;nbsp;three&amp;nbsp;jobs,&amp;nbsp;three files will be created:&lt;/P&gt;&lt;P&gt;OUTPUT_129692&lt;/P&gt;&lt;P&gt;OUTPUT_135534&lt;/P&gt;&lt;P&gt;OUTPUT_&lt;SPAN&gt;135512&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run the code below -- I cannot seem to get the export statement to subset the data successfully and output each individual file&lt;/P&gt;&lt;P&gt;The error returns %SCAN has too many arguments:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
%local i nextjob;
%do i=1 %to %sysfunc(countw("&amp;amp;job.",","));
%let nextjob = %scan(&amp;amp;job., &amp;amp;i);

 proc export data = temp.IDs_SUM (where=(jobid = "&amp;amp;nextjob."))
		outfile="/USERFOLDER/OUTPUT_&amp;amp;nextjob..xlsx"
		DBMS=XLSX REPLACE;
	run;

%end;
%mend loop;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any tips on what I am doing wrong?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 22:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452691#M69837</guid>
      <dc:creator>Terho</dc:creator>
      <dc:date>2018-04-09T22:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Export statement - Export multiple subset files via loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452692#M69838</link>
      <description>&lt;P&gt;Basic issue is including commas in a list that will be used as a macro parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try making the list look like this:&lt;/P&gt;
&lt;P&gt;129692 135534 135512&lt;/P&gt;
&lt;P&gt;such as&lt;/P&gt;
&lt;P&gt;%let job = 129692 135534 135512;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;also the quotes in the countw likely aren't needed&lt;/P&gt;
&lt;PRE&gt;%let job = 129692 135534 135512;

%macro dummy;
   %do i=1 %to %sysfunc(countw(&amp;amp;job," "));
      %let nextjob = %scan(&amp;amp;job.,&amp;amp;i);
      %put Nextjob is &amp;amp;nextjob ;
   %end;
%mend;

%dummy;&lt;/PRE&gt;
&lt;P&gt;Note that with the commas you were generating&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%scan(129692, 135534, 135512, &amp;amp;I) which is pretty obviously not quite correct.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 23:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452692#M69838</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-09T23:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Export statement - Export multiple subset files via loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452795#M69844</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let job = 129692,135534,135512 ;  %put &amp;amp;job;

%macro dummy;
   %do i=1 %to %sysfunc(countw(%bquote(&amp;amp;job),%str(,)));
      %let nextjob = %scan(%bquote(&amp;amp;job),&amp;amp;i);
      %put Nextjob is &amp;amp;nextjob ;
   %end;
%mend;

%dummy&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 13:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452795#M69844</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-04-10T13:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Export statement - Export multiple subset files via loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452819#M69845</link>
      <description>&lt;P&gt;Thank you Ksharp! This worked beautifully!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I guess the key point here is the use of the %bquote and %str function within the macro.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 13:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Proc-Export-statement-Export-multiple-subset-files-via-loop/m-p/452819#M69845</guid>
      <dc:creator>Terho</dc:creator>
      <dc:date>2018-04-10T13:38:41Z</dc:date>
    </item>
  </channel>
</rss>

