<?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: Macros to create excel output from a subset of sas datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156541#M298996</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;I modified yours a bit to see if without using the macro, I can get it one step at a time.&lt;BR /&gt;can I modify it to this?&amp;nbsp; (I'm new at this and would like to know the basic and then work thru the complex)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*read a few variables from the original dataset&lt;/P&gt;&lt;P&gt;-&amp;nbsp; data exportit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set output.filename;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; **(this calls all the variables in the original dataset)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep var1, var2, var5, var10&amp;nbsp; **(this keeps the few variables I need to export to xls)&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc export data = exportit;&lt;/P&gt;&lt;P&gt;outfile = 'G:\xyz\output\file1\var1.xls'&lt;/P&gt;&lt;P&gt;dbms=xls replace;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*(your original code);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.vtable (where=(libname="WORK" and index(upcase(memname),"TEST")&amp;gt;0));&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('proc export data=work.'||strip(memname)||' outfile="s:\temp\rob\'||strip(memname)||'.xls"; run;');&lt;/P&gt;&lt;P&gt;run&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Mar 2014 11:00:25 GMT</pubDate>
    <dc:creator>AnnMarie</dc:creator>
    <dc:date>2014-03-26T11:00:25Z</dc:date>
    <item>
      <title>Macros to create excel output from a subset of sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156537#M298992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;How do I use a macro to read in 15 datasets (with the same variables) - location G:\xyz\output (filenames follow the same format - example ab_city.sas7bdat, xx_city.sas7bdat, yz_city.sas7bdat.&lt;/P&gt;&lt;P&gt;- and export an excel output of a subset of the variables in separate excel files to one location (G:\xyz\output\city).&amp;nbsp; Each file will be saved as G\xyz\output\city\ab_city.xls.&lt;BR /&gt;I appreciate your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 01:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156537#M298992</guid>
      <dc:creator>AnnMarie</dc:creator>
      <dc:date>2014-03-26T01:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macros to create excel output from a subset of sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156538#M298993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a sketch, you'll have to specify your export exactly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname out '&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;G:\xyz\output&lt;/SPAN&gt;'; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select distinct memname into :file1-:file15 from dictionary.table&lt;/P&gt;&lt;P&gt;where libname="OUT" and upcase(memname) like "%_CITY";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;file1;&lt;/P&gt;&lt;P&gt;%put &amp;amp;file10;&lt;/P&gt;&lt;P&gt;%put &amp;amp;file15.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro export_files;&lt;/P&gt;&lt;P&gt;%do i=1 %to 15;&lt;/P&gt;&lt;P&gt;proc export data=&amp;amp;&amp;amp;file&amp;amp;i .....rest of export statements;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%export_files&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 01:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156538#M298993</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-03-26T01:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macros to create excel output from a subset of sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156539#M298994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding in comments to help you understand it... and cleaning it up &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS has a table called sashelp.vtable or Dictionary.table. Navigate to sashelp.vtable and take a look at it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will query that table and pull the table names into 15 macro variables file1 to file15. The where clause is used to filter the table, so lib name is the library as assigned and memname is the dataset name, where it starts anything but ends with _CITY.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Play around with different options to see what it returns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql noprint;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select distinct memname into :file1-:file15 from dictionary.table&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;where libname="OUT" and upcase(memname) like "%_CITY";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 02:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156539#M298994</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-03-26T02:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macros to create excel output from a subset of sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156540#M298995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just to add, in your methodology you could just write:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.vtable (where=(libname="WORK" and index(upcase(memname),"TEST")&amp;gt;0));&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('proc export data=work.'||strip(memname)||' outfile="s:\temp\rob\'||strip(memname)||'.xls"; run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note to replace WORK and TEST with your libname and filenames.&amp;nbsp; Saves all that macro processing. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 09:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156540#M298995</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-03-26T09:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macros to create excel output from a subset of sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156541#M298996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;I modified yours a bit to see if without using the macro, I can get it one step at a time.&lt;BR /&gt;can I modify it to this?&amp;nbsp; (I'm new at this and would like to know the basic and then work thru the complex)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*read a few variables from the original dataset&lt;/P&gt;&lt;P&gt;-&amp;nbsp; data exportit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set output.filename;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; **(this calls all the variables in the original dataset)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep var1, var2, var5, var10&amp;nbsp; **(this keeps the few variables I need to export to xls)&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc export data = exportit;&lt;/P&gt;&lt;P&gt;outfile = 'G:\xyz\output\file1\var1.xls'&lt;/P&gt;&lt;P&gt;dbms=xls replace;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*(your original code);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.vtable (where=(libname="WORK" and index(upcase(memname),"TEST")&amp;gt;0));&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('proc export data=work.'||strip(memname)||' outfile="s:\temp\rob\'||strip(memname)||'.xls"; run;');&lt;/P&gt;&lt;P&gt;run&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 11:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156541#M298996</guid>
      <dc:creator>AnnMarie</dc:creator>
      <dc:date>2014-03-26T11:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macros to create excel output from a subset of sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156542#M298997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No probs.&amp;nbsp; Let me explain the call execute first, this may clarify things.&amp;nbsp; Call execute takes a string and sends that string directly to the compiler rather than to the macro pre-processor.&amp;nbsp; The macro pre-processor is a bit like a find replace function where it expands all you code to full code before sending to the compiler, so it resolves macro variables, expands %if or %do loops etc.&amp;nbsp; What I am doing is creating the code I want to execute - and this can be any code - and utilizing the datastep which operates as a loop over each row to generate the code which gets sent to the compiler.&amp;nbsp; Here is an update following your request:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.vtable (where=(libname="WORK" and index(upcase(memname),"TEST")&amp;gt;0));&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('data work.exportit (keep=var1 var2 var5 var10); set work.'||strip(memname)||'; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc export data=work.exportit outfile="s:\temp\rob\'||strip(memname)||'.xls"; run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What this actually does is first creates a temporary dataset with all records from vtable where libname=WORK and TEST is in the dataset name.&amp;nbsp; Then for each of these rows creates a string - say we have two: x1_test and y1_test then there will be two strings sent to the compiler:&lt;/P&gt;&lt;P&gt;"data work.exportit (keep=var1 var2 var5 var10); set work.x1_test; run;&lt;/P&gt;&lt;P&gt;proc export data=work.exportit outfile="s:\temp\rob\x1_test.xls"; run;"&lt;/P&gt;&lt;P&gt;"data work.exportit (keep=var1 var2 var5 var10); set work.y1_test; run; &lt;/P&gt;&lt;P&gt;proc export data=work.exportit outfile="s:\temp\rob\y1_test.xls"; run;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you check the log when you run something like the above, you will see what is generated under the 'NOTE: CALL EXECUTE generate line' &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 11:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156542#M298997</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-03-26T11:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macros to create excel output from a subset of sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156543#M298998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much For the details!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 13:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-to-create-excel-output-from-a-subset-of-sas-datasets/m-p/156543#M298998</guid>
      <dc:creator>AnnMarie</dc:creator>
      <dc:date>2014-03-26T13:06:43Z</dc:date>
    </item>
  </channel>
</rss>

