<?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: file export macro with rename option in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521208#M4167</link>
    <description>&lt;OL&gt;&lt;LI&gt;Thanks for catching the missing &amp;amp;. As soon as I added that to the macro, it worked as intended&lt;/LI&gt;&lt;LI&gt;I'm not following why to use the STR() function.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Dec 2018 17:22:46 GMT</pubDate>
    <dc:creator>kb011235</dc:creator>
    <dc:date>2018-12-13T17:22:46Z</dc:date>
    <item>
      <title>file export macro with rename option</title>
      <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521169#M4152</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a saved macro that I use for exporting...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xport (lib,tbl) ;

proc export data = &amp;amp;lib..&amp;amp;tbl.
  outfile = "/sasuser/bailkx4/sasdata/export/&amp;amp;tbl..txt"
  dbms = tab
  replace ;
  run ;
  
%mend xport ;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;...and recently I was testing a SAS program where it would have been nice to be able to export the dataset with a new name after each procedure&amp;nbsp;in order to see how it&amp;nbsp;changed between each step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried modifying the macro to ...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xport (lib,tbl,rename) ;

proc export data = &amp;amp;lib..&amp;amp;tbl.
  %if rename NE '' %then
  outfile = "/sasuser/bailkx4/sasdata/export/&amp;amp;rename..txt";
  %Else
  outfile = "/sasuser/bailkx4/sasdata/export/&amp;amp;tbl..txt";
  dbms = tab
  replace ;
  run ;
  
%mend xport ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;...but when I tried exporting without indicating the rename argument (%xport(work,data)), the file name came out as ".txt" with no name. My intent was that the rename argument would be optional, so if nothing is passed into the rename argument, the default would be to name the file tbl. If the rename argument is passed into the macro, it works as intended. I would like to retain the original functionality, but with the additional capability of renaming the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help to solve this issue would be much appreciated. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 16:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521169#M4152</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2018-12-13T16:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: file export macro with rename option</title>
      <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521181#M4156</link>
      <description>1. you're mising an &amp;amp; before rename in your %IF statement. &lt;BR /&gt;2. Use %STR() instead to check for a blank value. 3. Make sure the semicolon ends up where it needs to be as well - the out at the end of the outfile statement.</description>
      <pubDate>Thu, 13 Dec 2018 16:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521181#M4156</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-13T16:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: file export macro with rename option</title>
      <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521184#M4157</link>
      <description>&lt;P&gt;You should provide an example of the actual macro call that misbehaved in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the code is as you posted:&lt;/P&gt;
&lt;PRE&gt;%if rename NE '' %then
&lt;/PRE&gt;
&lt;P&gt;is ALWAYS true because the text rename is not ''&lt;/P&gt;
&lt;PRE&gt;%macro dummy(rename);
   %if &amp;amp;rename ne '' %then %put Rename was: &amp;amp;rename;
%mend;

%dummy(word)
%dummy( )&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably meant to use&lt;/P&gt;
&lt;PRE&gt;%if &amp;amp;rename NE '' %then
&lt;/PRE&gt;
&lt;P&gt;so the resolved value of the rename macro variable is used for the comparison. But that has issues because blank is also not equal to ''. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro dummy(rename);
   %if &amp;amp;rename ne '' %then %put Rename was: &amp;amp;rename;
%mend;

%dummy(word)
%dummy( )&lt;/PRE&gt;
&lt;P&gt;Testing for blanks is slightly more complex (stolen from I don't remember where)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* macro to test macro parameters             */
/* returns 1 if the tested parameter is blank */
/* 0 otherwise, blank means all charaters are,*/
/* or are macro variables that resolve to a,  */
/* blank                                      */
/* param can be upto 65,531 characters long   */
/* if numeric and several 1000 digits long may*/
/* hang the session. (Windows 32 bit OS)      */
/* NOT a test for a NULL (zero length string) */
/* though may work for some of those as well  */

%macro isBlank(param);
%sysevalf(%superq(&amp;amp;param)=,boolean)
%mend isBlank;
&lt;/PRE&gt;
&lt;P&gt;And use as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %isblank(&amp;amp;rename) = 0 %then &amp;lt;your code for when the parameter is not blank&amp;gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 16:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521184#M4157</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-13T16:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: file export macro with rename option</title>
      <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521208#M4167</link>
      <description>&lt;OL&gt;&lt;LI&gt;Thanks for catching the missing &amp;amp;. As soon as I added that to the macro, it worked as intended&lt;/LI&gt;&lt;LI&gt;I'm not following why to use the STR() function.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 17:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521208#M4167</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2018-12-13T17:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: file export macro with rename option</title>
      <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521210#M4168</link>
      <description>&lt;P&gt;I usually just use %LENGTH() to test for empty parameters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xport (lib,tbl,filename) ;
%if not %length(&amp;amp;filename) %then %let filename=%sysfunc(lowcase(&amp;amp;tbl));

proc export data = &amp;amp;lib..&amp;amp;tbl.
  outfile = "/sasuser/bailkx4/sasdata/export/&amp;amp;filename..txt"
  dbms = tab
  replace 
;
run ;
  
%mend xport ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Dec 2018 17:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521210#M4168</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-13T17:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: file export macro with rename option</title>
      <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521211#M4169</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Thanks for your explanation. The dummy example was helpful and I really like the isblank macro. I'll be adding that one to my toolbox.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 17:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521211#M4169</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2018-12-13T17:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: file export macro with rename option</title>
      <link>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521213#M4170</link>
      <description>&lt;P&gt;Very clever, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 17:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/file-export-macro-with-rename-option/m-p/521213#M4170</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2018-12-13T17:31:32Z</dc:date>
    </item>
  </channel>
</rss>

