DATA Step, Macro, Functions and more

Quoting on SYSTASK command

Accepted Solution Solved
Reply
Super Contributor
Posts: 326
Accepted Solution

Quoting on SYSTASK command

I would like to seek help on my script regarding quotes in my systask command; The command string is actually built the way I want it but when it gets resolved in the systask command it already breaks. I need to nrquote the variables I have as it can be possible there are spaces in the paths and filenames.

 

Greatly appreciate your help. Thanks!

 

%let pyscripts=C:\pyscripts;
%let sourcefile=sample.csv;
%let targettable=sample;

/* Build string for command line execution */
%let command = activate myenv%nrstr(&&) python %nrquote("&pyscripts\load_source_file.py") %nrquote("&sourcefile") %nrquote("&targettable");
%put &command;

/* Call python script for loading files*/
systask command "&command"
	status=loadstat
;

 

 

 


Accepted Solutions
Solution
‎03-13-2017 10:29 PM
Super User
Posts: 7,764

Re: Quoting on SYSTASK command

Your macro variable command resolves to this:

activate myenv&& python "C:\pyscripts\load_source_file.py" "sample.csv" "sample"

in the systask statement, this resolves to:

systask command "activate myenv&& python "C:\pyscripts\load_source_file.py" "sample.csv" "sample""
	status=loadstat
;

So your command is just

activate myenv&& python 

and

C:\pyscripts\load_source_file.py

is misinterpreted as part of the systask statement parameters.

I suggest you use double double quotes where needed:

%let command = activate myenv%nrstr(&&) python %nrquote(""&pyscripts\load_source_file.py"") %nrquote(""&sourcefile"") %nrquote(""&targettable"");

or you start kicking people in the behind who have blanks in their filenames.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎03-13-2017 10:29 PM
Super User
Posts: 7,764

Re: Quoting on SYSTASK command

Your macro variable command resolves to this:

activate myenv&& python "C:\pyscripts\load_source_file.py" "sample.csv" "sample"

in the systask statement, this resolves to:

systask command "activate myenv&& python "C:\pyscripts\load_source_file.py" "sample.csv" "sample""
	status=loadstat
;

So your command is just

activate myenv&& python 

and

C:\pyscripts\load_source_file.py

is misinterpreted as part of the systask statement parameters.

I suggest you use double double quotes where needed:

%let command = activate myenv%nrstr(&&) python %nrquote(""&pyscripts\load_source_file.py"") %nrquote(""&sourcefile"") %nrquote(""&targettable"");

or you start kicking people in the behind who have blanks in their filenames.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 326

Re: Quoting on SYSTASK command

Posted in reply to KurtBremser

Thanks a lot for the help. The double quoting works and lets me execute the python script properly.

 

Oh, and the second suggestion works as well!! Will definitely impose that one! Smiley LOL

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 154 views
  • 0 likes
  • 2 in conversation