<?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: mainframe file copy to another file with date at the end of the new file name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626504#M184810</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path = /home/fkhurshed/Demo1;
%let new_path = /home/fkhurshed/Demo1/Sample;


*get listing of all files;
%*Creates a list of all files in the DIR directory with the specified extension (EXT);
%macro list_files(dir,ext);
	%local filrf rc did memcnt name i;
	%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
	%let did=%sysfunc(dopen(&amp;amp;filrf));

	%if &amp;amp;did eq 0 %then
		%do;
			%put Directory &amp;amp;dir cannot be open or does not exist;

			%return;
		%end;

	%do i = 1 %to %sysfunc(dnum(&amp;amp;did));
		%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

		%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then
			%do;
				%put &amp;amp;dir\&amp;amp;name;
				%let file_name =  %qscan(&amp;amp;name,1,.);
				%put &amp;amp;file_name;

				data _tmp;
					length dir $512 name $100;
					dir=symget("dir");
					name=symget("name");
					path = catx('/',dir,name);
					the_name = substr(name,1,find(name,'.')-1);
				run;

				proc append base=list data=_tmp force;
				run;

				quit;

				proc sql;
					drop table _tmp;
				quit;

			%end;
		%else %if %qscan(&amp;amp;name,2,.) = %then
			%do;
				%list_files(&amp;amp;dir/&amp;amp;name,&amp;amp;ext)
			%end;
	%end;

	%let rc=%sysfunc(dclose(&amp;amp;did));
	%let rc=%sysfunc(filename(filrf));
%mend list_files;

%list_files(&amp;amp;path, csv);

options msglevel=i;

data renameProcess;
set list;

*process to rename;
status_ref1 = filename('fr1', path);

*build filename with dates;
path2 = catt(dir, "/Sample/", name, "_", put(today(), yymmddn8.), ".csv");
status_ref2 = filename('fr2', path2);

*process to copy;
status_copy = fcopy('fr1', 'fr2');

   if status_copy=0 then
      put 'Copied SRC to DEST.';
   else do;
      msg=sysmsg();
      put status_copy= msg=;
   end;

run;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Feel free to replace the macro/listing program with your own steps. Basically it follows the steps I outlined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Get a list of files&lt;/LI&gt;
&lt;LI&gt;Create a fileref for each file using FILENAME()&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Use FCOPY to copy files&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Tested on SODA.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Feb 2020 16:23:09 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-02-21T16:23:09Z</dc:date>
    <item>
      <title>mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626328#M184716</link>
      <description>&lt;P&gt;Hello my expertise, in my shop, I have a requirement to copy about 600 mainframe flat files to another one with system date at end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FILE.ABCD.PDS&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;TO&amp;nbsp;&lt;/P&gt;&lt;P&gt;FILE.ABCD.PDS.D022020&amp;nbsp; (DMMDDYY)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried REXX. bit giving desired results. I cannot hard code the date because job runs thru ca7 scheduler.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible in SAS?&lt;/P&gt;&lt;P&gt;Please advise&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 20:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626328#M184716</guid>
      <dc:creator>Phil20</dc:creator>
      <dc:date>2020-02-20T20:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626332#M184719</link>
      <description>Yes it's possible. Use the FCOPY() and/or RENAME() functions. The documentations have examples of usage of each.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p14axci3mo3egan1okbcydvbt433.htm&amp;amp;docsetVersion=3.1&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p14axci3mo3egan1okbcydvbt433.htm&amp;amp;docsetVersion=3.1&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&amp;amp;docsetVersion=3.1&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&amp;amp;docsetVersion=3.1&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;FILENAME() function to assign filerefs as well.&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n15scht124hr4nn1g296cqg2kqfa.htm&amp;amp;docsetVersion=3.1&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n15scht124hr4nn1g296cqg2kqfa.htm&amp;amp;docsetVersion=3.1&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Thu, 20 Feb 2020 20:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626332#M184719</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-20T20:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626374#M184741</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;&lt;P&gt;I looked the fcopy function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="xis-code"&gt;filename src 'source.txt';
filename dest 'destination.txt';&lt;/PRE&gt;&lt;P&gt;In my case the destination file name is destination.system-date&lt;/P&gt;&lt;P&gt;how do I include the system date to the end of the destination file name dynamically?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 23:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626374#M184741</guid>
      <dc:creator>Phil20</dc:creator>
      <dc:date>2020-02-20T23:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626378#M184744</link>
      <description>You can build the file name as a string in the data step using regular SAS string/character functions and then pass to the FILENAME function. &lt;BR /&gt;&lt;BR /&gt;ext = catt(put(today, yymmddn8.), ".txt");&lt;BR /&gt;file_name_date = tranwrd(old_file_name, '.txt', ext);&lt;BR /&gt;&lt;BR /&gt;This would replace .txt with the extension 20200220.txt&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Feb 2020 23:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626378#M184744</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-20T23:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626379#M184745</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datestamp = D%sysfunc(today(),ddmmyy6.);
%put datestamp = &amp;amp;datestamp;

filename dest "destination&amp;amp;datestamp..txt";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2020 23:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626379#M184745</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-02-20T23:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626380#M184746</link>
      <description>That works but it's easier within a data step using the FILENAME() if you need to declare 600+ filerefs</description>
      <pubDate>Thu, 20 Feb 2020 23:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626380#M184746</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-20T23:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626387#M184748</link>
      <description>&lt;P&gt;If you've got an already working REXX then another option is to use SAS and generate this REXX with the filename/date you need, write the code to a file and then execute it using the internal reader (intrd).&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 03:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626387#M184748</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-21T03:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626388#M184749</link>
      <description>&lt;P&gt;REXX not working when I run it thru CA7 scheduler&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 03:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626388#M184749</guid>
      <dc:creator>Phil20</dc:creator>
      <dc:date>2020-02-21T03:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626504#M184810</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path = /home/fkhurshed/Demo1;
%let new_path = /home/fkhurshed/Demo1/Sample;


*get listing of all files;
%*Creates a list of all files in the DIR directory with the specified extension (EXT);
%macro list_files(dir,ext);
	%local filrf rc did memcnt name i;
	%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
	%let did=%sysfunc(dopen(&amp;amp;filrf));

	%if &amp;amp;did eq 0 %then
		%do;
			%put Directory &amp;amp;dir cannot be open or does not exist;

			%return;
		%end;

	%do i = 1 %to %sysfunc(dnum(&amp;amp;did));
		%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

		%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then
			%do;
				%put &amp;amp;dir\&amp;amp;name;
				%let file_name =  %qscan(&amp;amp;name,1,.);
				%put &amp;amp;file_name;

				data _tmp;
					length dir $512 name $100;
					dir=symget("dir");
					name=symget("name");
					path = catx('/',dir,name);
					the_name = substr(name,1,find(name,'.')-1);
				run;

				proc append base=list data=_tmp force;
				run;

				quit;

				proc sql;
					drop table _tmp;
				quit;

			%end;
		%else %if %qscan(&amp;amp;name,2,.) = %then
			%do;
				%list_files(&amp;amp;dir/&amp;amp;name,&amp;amp;ext)
			%end;
	%end;

	%let rc=%sysfunc(dclose(&amp;amp;did));
	%let rc=%sysfunc(filename(filrf));
%mend list_files;

%list_files(&amp;amp;path, csv);

options msglevel=i;

data renameProcess;
set list;

*process to rename;
status_ref1 = filename('fr1', path);

*build filename with dates;
path2 = catt(dir, "/Sample/", name, "_", put(today(), yymmddn8.), ".csv");
status_ref2 = filename('fr2', path2);

*process to copy;
status_copy = fcopy('fr1', 'fr2');

   if status_copy=0 then
      put 'Copied SRC to DEST.';
   else do;
      msg=sysmsg();
      put status_copy= msg=;
   end;

run;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Feel free to replace the macro/listing program with your own steps. Basically it follows the steps I outlined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Get a list of files&lt;/LI&gt;
&lt;LI&gt;Create a fileref for each file using FILENAME()&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Use FCOPY to copy files&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Tested on SODA.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 16:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626504#M184810</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-21T16:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626521#M184816</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;&lt;P&gt;its giving error on my input mainframe file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 *GET LISTING OF ALL FILES;&lt;BR /&gt;2 %*CREATES A LIST OF ALL FILES IN THE DIR DIRECTORY WITH THE SPECIFIED&lt;BR /&gt;3 EXTENSION (EXT);&lt;BR /&gt;4 %MACRO LIST_FILES(ITH78D.SASTEST.DATASETS,EXT);&lt;BR /&gt;ERROR: Symbolic variable name ITH78D.SASTEST.DATASETS must contain only letters,&lt;BR /&gt;ERROR: Symbolic variable name ITH78D.SASTEST.DATASETS must contain only letters,&lt;BR /&gt;ERROR: Symbolic variable name ITH78D.SASTEST.DATASETS must contain only letters,&lt;BR /&gt;ERROR: Invalid macro parameter name ITH78D.SASTEST.DATASETS. It should be a val&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 17:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626521#M184816</guid>
      <dc:creator>Phil20</dc:creator>
      <dc:date>2020-02-21T17:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626523#M184817</link>
      <description>Maybe a mainframe issue. I'm not sure how to get a list of files on the mainframe or reference filepaths for that matter.  The first parameter is the path....&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Feb 2020 17:32:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626523#M184817</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-21T17:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe file copy to another file with date at the end of the new file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626597#M184845</link>
      <description>&lt;P&gt;May be share your working REXX as this will define a bit better your input and desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure why the Ca7 scheduler should prohibit to execute a REXX especially when generated dynamically and then sent to the internal reader (=executes as a child process). In a time long long ago I've generated and executed this way jobs with JCL generated on-the-fly.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 04:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-file-copy-to-another-file-with-date-at-the-end-of-the/m-p/626597#M184845</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-22T04:10:06Z</dc:date>
    </item>
  </channel>
</rss>

