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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.