Hi
Below is the code i am using . I want to execute a job using X command in a datastep.
Path and Extn are macro variables. jobname is a datastep variable(from check dataset)
jobname is a variable which contains list of jobnames (like J_ABC,J_DEF etc) These are located under a mentioned location and extension is sh.Purpose is to execute those jobs using X command.
data _null_;
set check;
%let path=/app/scripts_p2/jobs;
%let extn=sh;
x "&path/jobname.&extn";
Kindly advise
Its getting retrieved as
/bin/ksh: /app/scripts_p2/jobs/jobname.sh: not found
Thanks,
Sandhya S
The X-statement is a "global" command that is not part of the datastep. You cannot get this to work. To do this you have to use the system function or Call routine.
Like rc = system( cats("&path/",jobname,".&extn") );
1) Have checked that /app/scripts_p2/jobs/jobname.sh file realy exist ?
2) Is the file executable ? - check unix permissions: user's and group's permission.
Then of course it cannot work as the result has unix sytax error:
/app/scripts_p2/jobs/ J_ABC,J_DEF.sh
You need to execute each job separatly.
Use SCAN funtion in a loop and execute the jobs one by one.
Within a data step, Build a string variable that has the code you want to execute, not Including the X. You can use the CATT function with macro variables and data step variables. Then use CALL SYSTEM to have it executed.
Data demo;
Set SASHELP.class;
Str = catt('string1', ....., “&path1.”, job);
*Call system(Str);
Run;
Untested.
@Sandy10 wrote:
Hi
Below is the code i am using . I want to execute a job using X command in a datastep.
Path and Extn are macro variables. jobname is a datastep variable(from check dataset)
jobname is a variable which contains list of jobnames (like J_ABC,J_DEF etc) These are located under a mentioned location and extension is sh.Purpose is to execute those jobs using X command.
data _null_;
set check;
%let path=/app/scripts_p2/jobs;
%let extn=sh;
x "&path/jobname.&extn";
Kindly advise
Its getting retrieved as
/bin/ksh: /app/scripts_p2/jobs/jobname.sh: not found
Thanks,
Sandhya S
The X-statement is a "global" command that is not part of the datastep. You cannot get this to work. To do this you have to use the system function or Call routine.
Like rc = system( cats("&path/",jobname,".&extn") );
This code
data _null_;
set check;
%let path=/app/scripts_p2/jobs;
%let extn=sh;
x "&path/jobname.&extn";
cant't work because X is a global statement that is executed as soon as it is encountered in the program text, so it will ALWAYS resolve to
x "/app/scripts_p2/jobs/jobname.sh";
with "jobname" being a literal. Use call system() instead, which is a data step subroutine:
%let path=/app/scripts_p2/jobs;
%let extn=sh;
data _null_;
set check;
call system("&path./" !! trim(jobname !! ".&extn.");
run;
Also note that it makes your code easier to grok when the macro statements are placed before the data step, because that is the order in which they are executed anyway.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.