- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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") );
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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") );
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.