<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic passing arguments to Python using X? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/passing-arguments-to-Python-using-X/m-p/473564#M121549</link>
    <description>&lt;P&gt;I'm looking for assistance making a call to Python scripts&amp;nbsp;(from SAS) while passing arguments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's some SAS code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET optionA = C:\temp\some_filename.csv;
%LET optionB = some text with spaces;
%LET optionC = text_with_underscores; 
%LET optionD = ;  /* an empty value */
%LET optionE = 15;

OPTIONS XWAIT;
X "C:\temp\test.py &amp;amp;optionA &amp;amp;optionB &amp;amp;optionC &amp;amp;optionD &amp;amp;optionE";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here's test.py&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import sys

optionA = sys.argv[1]
optionB = sys.argv[2]
optionC = sys.argv[3]
optionD = sys.argv[4]
optionE = sys.argv[5]

print 'optionA: ' + optionA
print 'optionB: ' + optionB
print 'optionC: ' + optionC
print 'optionD: ' + optionD
print 'optionE: ' + optionE

print 'Press Enter to return to SAS'
raw_input()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Running the SAS code results in the Python script executing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="python_screen.png" style="width: 457px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21426i8CFADAA6B9542071/image-size/large?v=v2&amp;amp;px=999" role="button" title="python_screen.png" alt="python_screen.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, optionB ends up being communicated as four separate one-word arguments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone please point out if there's a universal way of handling this, so each argument can contain any permissible combination of letters, numbers, and symbols, and is still treated as a single argument? I suppose some kind of escaping could be used, or maybe there's a completely different approach?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jun 2018 23:05:37 GMT</pubDate>
    <dc:creator>desertsp</dc:creator>
    <dc:date>2018-06-26T23:05:37Z</dc:date>
    <item>
      <title>passing arguments to Python using X?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-arguments-to-Python-using-X/m-p/473564#M121549</link>
      <description>&lt;P&gt;I'm looking for assistance making a call to Python scripts&amp;nbsp;(from SAS) while passing arguments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's some SAS code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET optionA = C:\temp\some_filename.csv;
%LET optionB = some text with spaces;
%LET optionC = text_with_underscores; 
%LET optionD = ;  /* an empty value */
%LET optionE = 15;

OPTIONS XWAIT;
X "C:\temp\test.py &amp;amp;optionA &amp;amp;optionB &amp;amp;optionC &amp;amp;optionD &amp;amp;optionE";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here's test.py&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import sys

optionA = sys.argv[1]
optionB = sys.argv[2]
optionC = sys.argv[3]
optionD = sys.argv[4]
optionE = sys.argv[5]

print 'optionA: ' + optionA
print 'optionB: ' + optionB
print 'optionC: ' + optionC
print 'optionD: ' + optionD
print 'optionE: ' + optionE

print 'Press Enter to return to SAS'
raw_input()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Running the SAS code results in the Python script executing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="python_screen.png" style="width: 457px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21426i8CFADAA6B9542071/image-size/large?v=v2&amp;amp;px=999" role="button" title="python_screen.png" alt="python_screen.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, optionB ends up being communicated as four separate one-word arguments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone please point out if there's a universal way of handling this, so each argument can contain any permissible combination of letters, numbers, and symbols, and is still treated as a single argument? I suppose some kind of escaping could be used, or maybe there's a completely different approach?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 23:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-arguments-to-Python-using-X/m-p/473564#M121549</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-06-26T23:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: passing arguments to Python using X?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-arguments-to-Python-using-X/m-p/473614#M121558</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;X "C:\temp\test.py '&amp;amp;optionA' '&amp;amp;optionB' '&amp;amp;optionC' '&amp;amp;optionD' '&amp;amp;optionE'";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because you have double quotes on the "outside", the single quotes contained "inside" do not prevent the resolution of macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 07:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-arguments-to-Python-using-X/m-p/473614#M121558</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-27T07:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: passing arguments to Python using X?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-arguments-to-Python-using-X/m-p/473756#M121608</link>
      <description>&lt;P&gt;Thanks Kurt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I get now:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="python_screen2.png" style="width: 455px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21446iA026E4E17EF67629/image-size/large?v=v2&amp;amp;px=999" role="button" title="python_screen2.png" alt="python_screen2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I think you've pointed me in the right direction. I now just need to find a way in Python to parse arguments at single-quotes rather than spaces, which shouldn't be a problem.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 14:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-arguments-to-Python-using-X/m-p/473756#M121608</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-06-27T14:32:46Z</dc:date>
    </item>
  </channel>
</rss>

