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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.