<?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: Export multiple datasets to multiple excel files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347664#M80363</link>
    <description>&lt;P&gt;Cool, this is the solution I will go with. Though I think you&amp;nbsp;may be missing a parenthesis somewhere, can I get you to test it out, I cant get it to export?&lt;/P&gt;</description>
    <pubDate>Thu, 06 Apr 2017 11:38:06 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-04-06T11:38:06Z</dc:date>
    <item>
      <title>Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347638#M80348</link>
      <description>&lt;P&gt;Hi all. I have a dataset 'have', which has an ID variable. Fo reach distinct value of ID, I want to create a want data set called want_ID and then I want to export this dataset to an excel file in a specific location. After creating the datasets I want to erase them again. How do I go about this the simplest way? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID $ var1 var2;
datalines;
1 100 200
4 300 400
4 500 200
4 200 100
7 400 200
1 300 166
1 300 100
7 400 400
;

data want_1;
	input ID $ var1 var2;
datalines;
1 100 200
1 300 166
1 300 100
;

data want_4;
	input ID $ var1 var2;
datalines;
4 300 400
4 500 200
4 200 100
;

data want_7;
	input ID $ var1 var2;
datalines;
7 400 200
7 400 400
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 09:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347638#M80348</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-06T09:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347640#M80349</link>
      <description>&lt;P&gt;If you use csv (or another textual format), you can change the outfile dynamically in a datastep (filevar= option). Just sort have by id and set the filevar= variable accordingly.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 09:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347640#M80349</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-06T09:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347641#M80350</link>
      <description>&lt;P&gt;Unfortunately I have to export as .xlsx format.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 09:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347641#M80350</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-06T09:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347642#M80351</link>
      <description>&lt;P&gt;Should be pretty simple, first list of unique IDs, then generate the exports (note I can't test at the moment, but should be near enough):&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=loop (keep=id) nodupkey;
  by id;
run;

data _null_;
  set loop;
  call execute('proc export data=have (where=(id="'||strip(id)||' outfile="c:\abc.xlsx";  sheet="'||strip(id)||'"; run;');
run;&lt;/PRE&gt;
&lt;P&gt;Note, I assumed id is character in the above.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 09:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347642#M80351</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-06T09:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347644#M80353</link>
      <description>&lt;P&gt;Very cool solution, did not think of data _NULL_ and doing this in a call execute myself. However, I have to export the three datasets to separate workbooks?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And btw, what is the logick behind the ||s in ||strip(id)||? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 10:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347644#M80353</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-06T10:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347647#M80354</link>
      <description>&lt;P&gt;Minor change then:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=loop (keep=id) nodupkey;
  by id;
run;

data _null_;
  set loop;
  call execute('proc export data=have (where=(id="'||strip(id)||' outfile="c:\abc'||strip(id)||'.xlsx";sheet="'||strip(id)||'"; run;');
run;&lt;/PRE&gt;
&lt;P&gt;This will create abc&amp;lt;id&amp;gt;.xlsx whre id changes each time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The double bar || means concatenate - its an older way of doing it, most of the time you would use catx, cats, catt etc. functions like:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=loop (keep=id) nodupkey;
  by id;
run;

data _null_;
  set loop;
  call execute(cats('proc export data=have (where=(id="',id,' outfile="c:\abc',id,'.xlsx";sheet="',id,'"; run;'));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 10:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347647#M80354</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-06T10:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347664#M80363</link>
      <description>&lt;P&gt;Cool, this is the solution I will go with. Though I think you&amp;nbsp;may be missing a parenthesis somewhere, can I get you to test it out, I cant get it to export?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 11:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347664#M80363</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-06T11:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347669#M80364</link>
      <description>&lt;P&gt;Yes, to clarify, the string returned by the cats() function needs to be valid code as that gets pushed out the compiler after the dataset stops executing, so you can see the generated code in the log with + symbol. &amp;nbsp;Makes debugging easier. &amp;nbsp;Anyways, this example works - using sashelp dataset:&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.class out=loop (keep=sex) nodupkey;
  by sex;
run;

data _null_;
  set loop;
  call execute(cats('proc export data=sashelp.class (where=(sex="',sex,'")) outfile="c:\test_',sex,'.xlsx";sheet="',sex,'"; run;'));
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Apr 2017 12:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347669#M80364</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-06T12:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Export multiple datasets to multiple excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347670#M80365</link>
      <description>&lt;P&gt;Cool, thank you so much for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 12:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-multiple-datasets-to-multiple-excel-files/m-p/347670#M80365</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-06T12:17:53Z</dc:date>
    </item>
  </channel>
</rss>

