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

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
;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

milts
Pyrite | Level 9

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 1439 views
  • 0 likes
  • 2 in conversation