<?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 Mask/Unmask Macrovar in %sysexecute - statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/418890#M102950</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot get my mind around an issue I am having with a call of a macro var within a %sysexec -statement.&lt;/P&gt;&lt;P&gt;I am executing several shell commands within one %sysexec - statement. Now, I'd like to loop this statement by using a macrovar in the "SELECT * FROM &amp;amp;TABLE" - part.&lt;/P&gt;&lt;P&gt;However, every time I execute this statement I do not get any error message, but there is nothing being written to the "test.txt" file either.&lt;/P&gt;&lt;P&gt;(&amp;lt;ssh credentials&amp;gt; and &amp;lt;mysql credentials&amp;gt; is not the problem).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I executed this step by replacing the &amp;amp;TABLE-macrovar with the real table name (i.e. "testtable") and it worked just fine&lt;/STRONG&gt;. I am pretty sure, it has got to do with masking/unmasking the macrovar. Can someone help me out with this issue?&lt;/P&gt;&lt;P&gt;I tried using %sysfunc(symget("TABLE")), but the symget function is not allowed with %sysfunc.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One problem could be, that the mysql - statement is in single quotes. But unfortunatelly, I cannot replace them with double quots, because then, the shell statement does not work anymore.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET TABLE = testtable;


%MACRO get_data_from_mysql;

%sysexec %str(ssh &amp;lt;SSH credentials&amp;gt;
			  'mysql &amp;lt;mysql credentials&amp;gt; -e 
			  "USE &amp;lt;schema&amp;gt;; SELECT * FROM &amp;amp;TABLE. ";'
			  &amp;gt; /path/to/my/folder/test.txt)
; 

%mend;

%get_data_from_mysql;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FK1&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2017 17:43:00 GMT</pubDate>
    <dc:creator>FK1</dc:creator>
    <dc:date>2017-12-06T17:43:00Z</dc:date>
    <item>
      <title>Mask/Unmask Macrovar in %sysexecute - statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/418890#M102950</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot get my mind around an issue I am having with a call of a macro var within a %sysexec -statement.&lt;/P&gt;&lt;P&gt;I am executing several shell commands within one %sysexec - statement. Now, I'd like to loop this statement by using a macrovar in the "SELECT * FROM &amp;amp;TABLE" - part.&lt;/P&gt;&lt;P&gt;However, every time I execute this statement I do not get any error message, but there is nothing being written to the "test.txt" file either.&lt;/P&gt;&lt;P&gt;(&amp;lt;ssh credentials&amp;gt; and &amp;lt;mysql credentials&amp;gt; is not the problem).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I executed this step by replacing the &amp;amp;TABLE-macrovar with the real table name (i.e. "testtable") and it worked just fine&lt;/STRONG&gt;. I am pretty sure, it has got to do with masking/unmasking the macrovar. Can someone help me out with this issue?&lt;/P&gt;&lt;P&gt;I tried using %sysfunc(symget("TABLE")), but the symget function is not allowed with %sysfunc.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One problem could be, that the mysql - statement is in single quotes. But unfortunatelly, I cannot replace them with double quots, because then, the shell statement does not work anymore.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET TABLE = testtable;


%MACRO get_data_from_mysql;

%sysexec %str(ssh &amp;lt;SSH credentials&amp;gt;
			  'mysql &amp;lt;mysql credentials&amp;gt; -e 
			  "USE &amp;lt;schema&amp;gt;; SELECT * FROM &amp;amp;TABLE. ";'
			  &amp;gt; /path/to/my/folder/test.txt)
; 

%mend;

%get_data_from_mysql;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FK1&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 17:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/418890#M102950</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2017-12-06T17:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Mask/Unmask Macrovar in %sysexecute - statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/418899#M102951</link>
      <description>&lt;P&gt;Here's a common way to control masking and unmasking.&amp;nbsp; It doesn't guarantee to solve all your problems, but it should get you through the first one at least:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token macroname"&gt;%sysexec&lt;/SPAN&gt; &lt;FONT color="#00ccff"&gt;%unquote(&lt;/FONT&gt;&lt;SPAN class="token macrostatement"&gt;%str&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ssh &lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt;SSH credentials&lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &amp;nbsp; &lt;FONT color="#ff0000"&gt;%&lt;/FONT&gt;&lt;SPAN class="token string"&gt;&lt;FONT color="#ff0000"&gt;'&lt;/FONT&gt;mysql &amp;lt;mysql credentials&amp;gt; -e "USE &amp;lt;schema&amp;gt;; SELECT * FROM &amp;amp;TABLE. ";&lt;FONT color="#ff0000"&gt;%'&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &amp;nbsp; &lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;path&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;to&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;my&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;folder&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;test&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;txt&lt;SPAN class="token punctuation"&gt;) &lt;FONT color="#00ccff"&gt;)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 17:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/418899#M102951</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-06T17:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Mask/Unmask Macrovar in %sysexecute - statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/418935#M102957</link>
      <description>Thanks Astounding! That's it! You are astounding &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 06 Dec 2017 20:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/418935#M102957</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2017-12-06T20:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Mask/Unmask Macrovar in %sysexecute - statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/421118#M103596</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do want to pick up on this topic again, as I am still having troubles:&lt;BR /&gt;&lt;BR /&gt;Like last time I want to execute a shell command from within SAS, but this time using %unquote(%nrbquote(.....)) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;%sysexec  %unquote(%nrbquote(
ssh johndoe@some.server.host
&amp;lt;MYSQL credentials&amp;gt; &amp;gt; /home/some/path/test42.txt
&amp;lt;&amp;lt;&amp;lt; "select * from information_schema.TABLES WHERE table_schema = 'some_value' "));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do get neither Errors nor Warnings, however, when I&amp;nbsp; %PUT the &amp;amp;SYSRC. I can see, it has a value of "2", i.e. ERROR-message.&lt;/P&gt;&lt;P&gt;I do know for sure that the shell command is correct, as I tested it interactively in the shell prompt and it worked just fine, meaning: it "filled" the textfile "test42".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's going on herre?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 15:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-Unmask-Macrovar-in-sysexecute-statement/m-p/421118#M103596</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2017-12-14T15:11:48Z</dc:date>
    </item>
  </channel>
</rss>

