BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sandy10
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
PSNn
Obsidian | Level 7

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") );

View solution in original post

7 REPLIES 7
Shmuel
Garnet | Level 18

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.

Sandy10
Calcite | Level 5
Hi Shumel. Ok, I think my post is not clear. 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.
Shmuel
Garnet | Level 18

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.

Reeza
Super User

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. 

Reeza
Super User

@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


 

PSNn
Obsidian | Level 7

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") );

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2358 views
  • 0 likes
  • 5 in conversation