<?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: How to simplify the proc export? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368671#M64987</link>
    <description>&lt;P&gt;This blog entry &lt;A href="http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/" target="_blank"&gt;http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/&lt;/A&gt; by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt; shows a very good example of a programming pattern executing the same code but with different values for certain statements and options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you&amp;nbsp; would list all the different values for macro vars x1 - x3 in a SAS data set in one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use the following macro sample to work through a list:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro iterator(valueList=);
  %local i value;
  %let i = 1;
  %let value = %scan(&amp;amp;valueList, &amp;amp;i);
  %do %while( &amp;amp;value ne );
    %put NOTE: &amp;amp;sysmacroname processing &amp;amp;=value;
    /* do something here, your SAS code */

    %let i = %eval(&amp;amp;i + 1);
    %let value = %scan(&amp;amp;valueList, &amp;amp;i);
  %end;
%mend;

%iterator(valueList=ID Time Place)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jun 2017 11:44:12 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2017-06-20T11:44:12Z</dc:date>
    <item>
      <title>How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368667#M64986</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the 21 program are very similar as the&amp;nbsp;following.&amp;nbsp; Is there a way to make the codes shorter?&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%Let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Folder=path;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%Let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; X1=ID;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%Let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; X2=Time;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%Let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; X3=Place;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;EXPORT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;DATA&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&amp;amp;X1 &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;outfile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&amp;amp;folder&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;dbms&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=xlsx &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;replace&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;sheet=&amp;amp;X1;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;EXPORT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;DATA&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&amp;amp;X2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;outfile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&amp;amp;folder&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;dbms&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=xlsx &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;replace&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;sheet=&amp;amp;X2;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;EXPORT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;DATA&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&amp;amp;X3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;outfile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&amp;amp;folder&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;dbms&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=xlsx &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;replace&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;sheet=&amp;amp;X3;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 11:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368667#M64986</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-20T11:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368671#M64987</link>
      <description>&lt;P&gt;This blog entry &lt;A href="http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/" target="_blank"&gt;http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/&lt;/A&gt; by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt; shows a very good example of a programming pattern executing the same code but with different values for certain statements and options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you&amp;nbsp; would list all the different values for macro vars x1 - x3 in a SAS data set in one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use the following macro sample to work through a list:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro iterator(valueList=);
  %local i value;
  %let i = 1;
  %let value = %scan(&amp;amp;valueList, &amp;amp;i);
  %do %while( &amp;amp;value ne );
    %put NOTE: &amp;amp;sysmacroname processing &amp;amp;=value;
    /* do something here, your SAS code */

    %let i = %eval(&amp;amp;i + 1);
    %let value = %scan(&amp;amp;valueList, &amp;amp;i);
  %end;
%mend;

%iterator(valueList=ID Time Place)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 11:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368671#M64987</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-06-20T11:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368680#M64989</link>
      <description>&lt;P&gt;Do you have SAS 9.4? &amp;nbsp;If so the you can use either:&lt;/P&gt;
&lt;PRE&gt;libname excel tmp "file.xlsx";
data tmp.id;
  set id;
run;
...
libname tmp clear;&lt;/PRE&gt;
&lt;P&gt;Or you can use ods excel. &amp;nbsp;Both create native Excel files, and ods excel will allow you to use proc report which gives you all the formatting options. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 12:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368680#M64989</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-20T12:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368681#M64990</link>
      <description>&lt;P&gt;How to create repeating code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 1: create one working instance of code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc export
  data=id
  outfile=path
  dbms=xlsx
  replace
;
sheet=id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE&gt;Step 2: identify variable parts and replace with macro variables:&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dataname=id;
%let folder=path;

proc export
  data=&amp;amp;dataname
  outfile=&amp;amp;folder
  dbms=xlsx
  replace
;
sheet=&amp;amp;dataname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Step 3: wrap into a macro, use the macro variables as parameters and call that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro repeat_code(dataname,folder);
proc export
  data=&amp;amp;dataname
  outfile=&amp;amp;folder
  dbms=xlsx
  replace
;
sheet=&amp;amp;dataname;
run;
%mend;

%repeat_code(id,path)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Step 4: create a means to repeat that code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data control;
input dataname $ folder $;
cards;
id path
time path
place path
;
run;

data _null_;
set control;
call execute('%repeat_code(' !! trim(dataname) !! ',' !! trim(folder) !! ') ');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Test at every step to make sure it's working before adding further complexity (Maxim 34). Scan the log thoroughly (Maxim 2).&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 12:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368681#M64990</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-20T12:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368686#M64991</link>
      <description>&lt;P&gt;If it is really just putting mutlple sheets into the same workbook then try using a LIBNAME instead of PROC EXPORT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname out xlsx "path" ;
proc copy inlib=work outlib=out;
 select ID Time Place;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jun 2017 12:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368686#M64991</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-20T12:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368689#M64992</link>
      <description>&lt;PRE&gt; Why not PROC COPY ? 
libname x xlsx 'c:\temp\x.xlsx';
proc copy in=work out=x;
select x1 x2;
run;   &lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jun 2017 12:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368689#M64992</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-20T12:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368697#M64993</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Very nice write-up! Can be used as a&amp;nbsp;How-to&amp;nbsp;tutorial for Macro beginners.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 13:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368697#M64993</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-06-20T13:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify the proc export?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368699#M64994</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Very nice write-up! Can be used as a&amp;nbsp;How-to&amp;nbsp;tutorial for Macro beginners.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;lt;blush&amp;gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 13:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-simplify-the-proc-export/m-p/368699#M64994</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-20T13:06:23Z</dc:date>
    </item>
  </channel>
</rss>

