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.
Eg:
FILE.ABCD.PDS
TO
FILE.ABCD.PDS.D022020 (DMMDDYY)
I tried REXX. bit giving desired results. I cannot hard code the date because job runs thru ca7 scheduler.
Is this possible in SAS?
Please advise
Hi Reeza
I looked the fcopy function.
filename src 'source.txt'; filename dest 'destination.txt';
In my case the destination file name is destination.system-date
how do I include the system date to the end of the destination file name dynamically?
%let datestamp = D%sysfunc(today(),ddmmyy6.);
%put datestamp = &datestamp;
filename dest "destination&datestamp..txt";
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).
REXX not working when I run it thru CA7 scheduler
%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,&dir));
%let did=%sysfunc(dopen(&filrf));
%if &did eq 0 %then
%do;
%put Directory &dir cannot be open or does not exist;
%return;
%end;
%do i = 1 %to %sysfunc(dnum(&did));
%let name=%qsysfunc(dread(&did,&i));
%if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then
%do;
%put &dir\&name;
%let file_name = %qscan(&name,1,.);
%put &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(&name,2,.) = %then
%do;
%list_files(&dir/&name,&ext)
%end;
%end;
%let rc=%sysfunc(dclose(&did));
%let rc=%sysfunc(filename(filrf));
%mend list_files;
%list_files(&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;
Feel free to replace the macro/listing program with your own steps. Basically it follows the steps I outlined.
Tested on SODA.
Hi Reeza
its giving error on my input mainframe file
1 *GET LISTING OF ALL FILES;
2 %*CREATES A LIST OF ALL FILES IN THE DIR DIRECTORY WITH THE SPECIFIED
3 EXTENSION (EXT);
4 %MACRO LIST_FILES(ITH78D.SASTEST.DATASETS,EXT);
ERROR: Symbolic variable name ITH78D.SASTEST.DATASETS must contain only letters,
ERROR: Symbolic variable name ITH78D.SASTEST.DATASETS must contain only letters,
ERROR: Symbolic variable name ITH78D.SASTEST.DATASETS must contain only letters,
ERROR: Invalid macro parameter name ITH78D.SASTEST.DATASETS. It should be a val
May be share your working REXX as this will define a bit better your input and desired output.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.