I am trying to use %sysexec chmod to set permission for files
issue is files are named with the timestamp which is hard to add in the code itself
any suggested workarounds?
files names like the below:
CORE_BANK_OUT1_20200423T145023.txt
@MAGED_AKL wrote:
the need is to give permission to all files starting with the fixed prefix "CORE_BANK_OUT"
Well, that's easy, as chmod accepts a list of files, and the shell expands wildcards:
filename oscmd pipe "chmod 600 /sas/SASConfig/Lev1/Applications/SASComplianceSolutions/FCFBU1/reports/risk_rating_report/Finished/SAS_CORE_BANK_OUT* 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
(replace the 600 with whatever permissions you need)
As chmod remains "silent" if everything is OK, a look at the SAS log will tell you if something untoward happened.
Try first to get that working out of a command prompt without using SAS at all.
You could Google with keywords like: linux chmod multiple files
Once you've got the OS command working and you need to call it via SAS then I'd go for a Filename Pipe approach over using %sysexec()
What do you know about the files? Do they all start with CORE_BANK_OUT1_? Or do you need to apply your chmod for all files with a specific timestamp?
The common criteria will define which logic to use.
The format of your timestamp is "basic ISO", for which SAS provides the format B8601DT15.
files are extracted using a sas code on a AIX environment
data _null_;
call symputx('timestamp',put(datetime(),B8601DT.));
run;
PROC EXPORT DATA=CORE_BANK_OUTT&i
OUTFILE="/sas/SASConfig/Lev1/Applications/SASComplianceSolutions/FCFBU1/reports/risk_rating_report/Finished/SAS_CORE_BANK_OUT&i._×tamp..txt"
DBMS=dlm REPLACE;
DELIMITER='|';
RUN;
where &i represents the sequence of the file
the need is to give permission to all files starting with the fixed prefix "CORE_BANK_OUT"
@MAGED_AKL wrote:
the need is to give permission to all files starting with the fixed prefix "CORE_BANK_OUT"
Well, that's easy, as chmod accepts a list of files, and the shell expands wildcards:
filename oscmd pipe "chmod 600 /sas/SASConfig/Lev1/Applications/SASComplianceSolutions/FCFBU1/reports/risk_rating_report/Finished/SAS_CORE_BANK_OUT* 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
(replace the 600 with whatever permissions you need)
As chmod remains "silent" if everything is OK, a look at the SAS log will tell you if something untoward happened.
Worked great
Thanks
@MAGED_AKL wrote:
files are extracted using a sas code on a AIX environment
data _null_;
call symputx('timestamp',put(datetime(),B8601DT.));
run;PROC EXPORT DATA=CORE_BANK_OUTT&i
OUTFILE="/sas/SASConfig/Lev1/Applications/SASComplianceSolutions/FCFBU1/reports/risk_rating_report/Finished/SAS_CORE_BANK_OUT&i._×tamp..txt"
DBMS=dlm REPLACE;
DELIMITER='|';
RUN;
where &i represents the sequence of the file
the need is to give permission to all files starting with the fixed prefix "CORE_BANK_OUT"
If above is the process which creates the files then you could eventually set a UMASK before so the files get created with the desired permissions from start.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.