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
;
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.
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.
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! ![]()
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.