- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p14axci3mo3egan1okbcydvbt433.htm...
https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm...
FILENAME() function to assign filerefs as well.
https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n15scht124hr4nn1g296cqg2kqfa.htm...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
ext = catt(put(today, yymmddn8.), ".txt");
file_name_date = tranwrd(old_file_name, '.txt', ext);
This would replace .txt with the extension 20200220.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let datestamp = D%sysfunc(today(),ddmmyy6.);
%put datestamp = &datestamp;
filename dest "destination&datestamp..txt";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
REXX not working when I run it thru CA7 scheduler
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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.
- Get a list of files
- Create a fileref for each file using FILENAME()
- Use FCOPY to copy files
Tested on SODA.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.