<?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: Filename statement in a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882042#M348494</link>
    <description>&lt;P&gt;Try calling your macro as one statement to get it right:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%zip(file_name=MyExcelFile); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that works then try the CALL EXECUTE version.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2023 22:41:07 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2023-06-22T22:41:07Z</dc:date>
    <item>
      <title>Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882039#M348493</link>
      <description>&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following SAS code which is to move a xlsx file to a zip file works perfectly,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;filename xfile "y\test.xlsx" recfm=n;
filename zfile zip "y\archive\Processed.zip" member="test.xlsx" recfm=n;
data _null_;
  rc=fcopy('xfile','zfile');
  put rc=;
  rc=fdelete('xfile')
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, there are multiple xlsx files in the same directory need to be moved to the zip file. I put the above code in a Macro, but the filename statement not working in a Macro.&lt;/P&gt;&lt;PRE&gt;%macro zip (file_name=);&lt;BR /&gt;filename xfile "y\&amp;amp;file_name..xlsx" recfm=n;&lt;BR /&gt;filename zfile zip "y\archive\Processed.zip" member="&amp;amp;file_name..xlsx" recfm=n;&lt;BR /&gt;data _null_;&lt;BR /&gt;rc=fcopy('xfile','zfile');&lt;BR /&gt;put rc=;&lt;BR /&gt;rc=fdelete('xfile');&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set files;&lt;BR /&gt;call execute('%nrstr(%zip(file_name='||strip(file_name)||'))'); &lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;Can you please advise how to modify the second SAS code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2023 21:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882039#M348493</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-22T21:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882042#M348494</link>
      <description>&lt;P&gt;Try calling your macro as one statement to get it right:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%zip(file_name=MyExcelFile); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that works then try the CALL EXECUTE version.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2023 22:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882042#M348494</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-06-22T22:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882046#M348496</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I tried your suggest, it works for&lt;BR /&gt;%zip(file_name=MyExcelFile);&lt;BR /&gt;&lt;BR /&gt;However, once I use Call Execute, it's not working...</description>
      <pubDate>Thu, 22 Jun 2023 23:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882046#M348496</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-22T23:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882048#M348498</link>
      <description>It works for %zip(file_name=MyExcelFile); But still not working for Call Execute.&lt;BR /&gt;&lt;BR /&gt;When I run %zip(file_name=MyExcelFile); The log says rc=0. However, If I run Call Execute, rc=20006.&lt;BR /&gt;&lt;BR /&gt;I have no clue why this is</description>
      <pubDate>Thu, 22 Jun 2023 23:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882048#M348498</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-22T23:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882049#M348499</link>
      <description>&lt;P&gt;Try this. Looks like you are missing a semicolon between macro calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('%nrstr(%zip(file_name='||strip(file_name)||');)');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2023 23:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882049#M348499</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-06-22T23:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882052#M348501</link>
      <description>It still doesn't work...</description>
      <pubDate>Thu, 22 Jun 2023 23:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882052#M348501</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-22T23:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882054#M348502</link>
      <description>&lt;P&gt;It can be tricky to get CALL EXECUTE to behave. I've found constructing the EXEC statement separately helps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set files;
  exec_stmt = '%zip(file_name=' !! strip(file_name) !!');';
  call execute('%nrstr(' !! exec_stmt !! ')');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jun 2023 00:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882054#M348502</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-06-23T00:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882064#M348504</link>
      <description>&lt;P&gt;I would not wrap %NRSTR() around the whole command.&amp;nbsp; Just the macro name.&amp;nbsp; I would not add quotes into the MIDDLE of the filename by adding them into the macro parameter value.&amp;nbsp; If your file names might strange characters like commas that could confuse the macro processor you might need to add another level of %NRSTR() so that the result is that CALL EXECUTE() pushes a string like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%zip(filename=%nrstr(my file name with a comma, in it))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;onto the stack to run after the macro finishes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set files;
  call execute(cats('%nrstr(%zip)(file_name=%nrstr(%nrstr(',file_name,')))' ));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;But the real answer is to NOT use the FILENAME statement or a macro.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Instead use the FILENAME() function. Then you don't need to do any code generation at all.&amp;nbsp; Just a single data step to process the whole input dataset with the filenames.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like (play with the arguments to the FILENAME() function to get it right).&amp;nbsp; You also probably need to figure out what return code from FDELETE() means it worked. And possibly what return codes for the other function calls mean they worked.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set files;
  rc1=filename('xfile',cats('y\',file_name,'.xlsx'),,'recfm=n');
  rc2=filename('zfile','y\archive\Processed.zip','zip'
              ,catx(' ',cats('member=',quote(cats(file_name,'.xlsx'))),'recfm=n'));
  rc3=fcopy('xfile','zfile');
  if rc3=XXXX then do;
      * It worked ;
      rc4=fdelete('xfile');
  end;
  rc5=filename('xfile');
  rc6=filename('zfile');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jun 2023 04:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882064#M348504</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-23T04:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882109#M348518</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308056"&gt;@wbsjd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I tried your suggest, it works for&lt;BR /&gt;%zip(file_name=MyExcelFile);&lt;BR /&gt;&lt;BR /&gt;However, once I use Call Execute, it's not working...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"It's not working" is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If macro code is involved set OPTIONS MPRINT; prior to running the code and then follow the above about LOG contents.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 10:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882109#M348518</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-23T10:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882145#M348532</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308056"&gt;@wbsjd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I tried your suggest, it works for&lt;BR /&gt;%zip(file_name=MyExcelFile);&lt;BR /&gt;&lt;BR /&gt;However, once I use Call Execute, it's not working...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suspect it is a timing issue.&amp;nbsp; Try running two or more macro calls without the data step.&amp;nbsp; Do the second and third work?&amp;nbsp; Which steps are failing? The filename statements?&amp;nbsp; The FCOPY() function call? The FDELETE() function call?&amp;nbsp;&amp;nbsp; Check the return codes after each step.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that SAS is having a hard time reusing the XFILE fileref because the operating system has not really finished with the deletion or the copy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps SAS is having a hard time re-opening the ZIP file to add new files.&amp;nbsp; Not clear how it does that but I would not be surprised if it would help to add some delays between the steps to let it finish updating the ZIP file on the disk before trying to add another entry into it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 14:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882145#M348532</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-23T14:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882200#M348553</link>
      <description>&lt;P&gt;If I run the following code, the 4 xlsx files will be added to the Zip files&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%zip(file_name=test); 
%zip(file_name=test1); 
%zip(file_name=test2); 
%zip(file_name=test3); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SAS Log for the above code&amp;nbsp; is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wbsjd_1-1687543761346.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85321i80F64D9FE4AAE85F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wbsjd_1-1687543761346.png" alt="wbsjd_1-1687543761346.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If I run the code, no xlsx files is moved to the zip file&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set files;
  call execute(cats('%nrstr(%zip)(file_name=%nrstr(%nrstr(',file_name,')))' ));
run;
or 
data _null_;
set files;
call execute('%nrstr(%zip(file_name='||strip(file_name)||'))');run;&lt;/PRE&gt;
&lt;P&gt;The SAS Log is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wbsjd_2-1687543926140.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85322i92045EE622F4F767/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wbsjd_2-1687543926140.png" alt="wbsjd_2-1687543926140.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really don't know what's the issue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 18:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882200#M348553</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-23T18:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882206#M348554</link>
      <description>&lt;P&gt;When I run the following code all together, all 4 xlsx files are moved to the zip file&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%zip(file_name=test); 
%zip(file_name=test1); 
%zip(file_name=test2); 
%zip(file_name=test3); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SAS Log is like&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wbsjd_1-1687544546386.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85324i4D41BC50D361C7B0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wbsjd_1-1687544546386.png" alt="wbsjd_1-1687544546386.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run one of the following code, no file is moved to the zip file, and the SAS log for the following code is almost the same&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set files;
  call execute(cats('%nrstr(%zip)(file_name=%nrstr(%nrstr(',file_name,')))' )); run;
or
data _null_;
  set files;
  exec_stmt = '%zip(file_name=' !! strip(file_name) !!');';
  call execute('%nrstr(' !! exec_stmt !! ')'); run;
or
data _null_;
set files;
call execute('%nrstr(%zip(file_name='||strip(file_name)||'))');run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SAS Log show no error and is like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wbsjd_2-1687544761104.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85325i1DE1C2D8F1583DBE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wbsjd_2-1687544761104.png" alt="wbsjd_2-1687544761104.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I really don't know what's the issue.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 18:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882206#M348554</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-23T18:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882208#M348555</link>
      <description>&lt;P&gt;I tried your code, and also other Call Execute code. The xlsx files are&amp;nbsp; still not successfully moved to the zip file. The log for your code and the following code is roughly the same....&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Call Execute provided by others:&lt;BR /&gt;data _null_;
  set files;
  call execute(cats('%nrstr(%zip)(file_name=%nrstr(%nrstr(',file_name,')))' ));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jun 2023 18:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882208#M348555</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-23T18:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882214#M348560</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Posting photographs of text makes it harder to respond.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The two are not trying to move the same files.&lt;/P&gt;
&lt;P&gt;The manual macro calls did not include a .xlsx extension on the name being passed to the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the names of the files?&lt;/P&gt;
&lt;P&gt;test ?&lt;/P&gt;
&lt;P&gt;or test.xlsx&lt;/P&gt;
&lt;P&gt;or test.xlsx.xlsx ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 19:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882214#M348560</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-23T19:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882228#M348568</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro zip (file_name=);
filename xfile "y\&amp;amp;file_name..xlsx" recfm=n;
filename zfile zip "y\archive\Processed.zip" member="&amp;amp;file_name..xlsx" recfm=n;
data _null_;
rc=fcopy('xfile','zfile');
put rc=;
rc=fdelete('xfile');
run;
%mend;

%zip(file_name=test); 
%zip(file_name=test1); 
%zip(file_name=test2); 
%zip(file_name=test3); 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The .xlsx is already in the Macro, the name of the file is test.xlsx&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 20:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882228#M348568</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-23T20:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882230#M348570</link>
      <description>&lt;P&gt;Then why did you call it from the data step with the extra .xlsx added?&lt;/P&gt;
&lt;P&gt;From the photograph you posted of your SAS log your data step generated this command:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%zip(file_name=%nrstr(test.xlsx)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of the the command you wanted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%zip(file_name=%nrstr(test)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fix one of the&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The input dataset with the list of file names.&lt;/LI&gt;
&lt;LI&gt;The macro to not add the .xlsx.&lt;/LI&gt;
&lt;LI&gt;The data step to remove the .xlsx.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 23 Jun 2023 20:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882230#M348570</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-23T20:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882232#M348571</link>
      <description>&lt;P&gt;You are right!&amp;nbsp; It is because the extra .xlsx in the Macro....... After I remove the xlsx in the Macro, the code works as assumed.&amp;nbsp; I should check it carefully&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":sad_but_relieved_face:"&gt;😥&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 20:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882232#M348571</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2023-06-23T20:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Filename statement in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882237#M348572</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308056"&gt;@wbsjd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The SAS Log show&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; no error&lt;/STRONG&gt;&lt;/FONT&gt; and is like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wbsjd_2-1687544761104.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85325i1DE1C2D8F1583DBE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wbsjd_2-1687544761104.png" alt="wbsjd_2-1687544761104.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I really don't know what's the issue.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I highlighted an error in your understanding above. Your output clearly shows RC=20006.&lt;/P&gt;
&lt;P&gt;From the documentation of the FCOPY function, which is what your Put RC= would be printing from your %ZIP macro,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="p1ig0o6ls5vhezn1n5dtxdvbjr0y" class="xis-subTopic"&gt;
&lt;H3 class="xis-title"&gt;Values That Are Returned by the FCOPY Function&lt;/H3&gt;
&lt;DIV id="n0uqsvus0vfgfhn10gfi32kza44t" class="xis-topicContent"&gt;
&lt;DIV id="p02v8d4l7pnkcen16n553uhmgd3t" class="xis-paragraph"&gt;FCOPY returns these values:
&lt;DIV class="xis-listUnordered"&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV id="n0gza7rwip2dlyn1980uz1hzeytq" class="xis-item"&gt;
&lt;DIV id="p0iwwh6teoxkeyn1x9p1fj4npbpo" class="xis-paraSimpleFirst"&gt;a value of 0 if records were copied without errors or warnings&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV id="p1l1vdb9knc72an10k7io1p0wrw9" class="xis-item"&gt;
&lt;DIV id="p1sbapj52u0425n11llsp6gw5k8j" class="xis-paraSimpleFirst"&gt;&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;a positive value if an error occurred&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV id="n0vf1mgfs9jxzin1ap34nb2j5xdb" class="xis-item"&gt;
&lt;DIV id="n0o7cus97a8xj7n17pgxiatrhqam" class="xis-paraSimpleFirst"&gt;a negative value if a warning was issued&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The magenta is where you did not understand that your code was throwing an error.&lt;/P&gt;
&lt;P&gt;Follow up with:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="p1ig0o6ls5vhezn1n5dtxdvbjr0y" class="xis-subTopic"&gt;
&lt;DIV id="n0uqsvus0vfgfhn10gfi32kza44t" class="xis-topicContent"&gt;
&lt;DIV id="p1avpjbd1li1u8n1vjdzszn325im" class="xis-paragraph"&gt;You can use the SYSMSG function to retrieve error or warning messages, and you can use the SYSRC function to retrieve the return code.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you might use something like&lt;/P&gt;
&lt;PRE&gt;if rc ne 0 then do;
   message=sysmsg();
   put message;
end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 22:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filename-statement-in-a-Macro/m-p/882237#M348572</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-23T22:09:33Z</dc:date>
    </item>
  </channel>
</rss>

