<?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 Re: Why does %SYSFUNC(DOSUBL() remove outer quotes? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561675#M157283</link>
    <description>&lt;P&gt;It's not only when called via a macro that the surrounding single quotes are removed.&lt;/P&gt;
&lt;P&gt;This runs fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  RC=dosubl("  'data _null_;  string=symget(""sysjobid"");  put string;run;'  ");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[Edit: This code does NOT run as expected.]&lt;/P&gt;</description>
    <pubDate>Mon, 27 May 2019 21:35:11 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-05-27T21:35:11Z</dc:date>
    <item>
      <title>Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561622#M157260</link>
      <description>&lt;P&gt;An interesting puzzle was raised by this question.&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Changing-SAS-System-options-within-a-macro-which-does-not/td-p/561562" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Changing-SAS-System-options-within-a-macro-which-does-not/td-p/561562&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I try to run a line of code with single quotes around it then SAS will rightly throw an error message because you cannot have a free floating string literal in the middle of a block of SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why does SAS remove the quotes around values passed to the DOSUBL() function when called via the %SYSFUNC() macro call?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if I make a program file with this value:&lt;/P&gt;
&lt;PRE&gt;&amp;gt;more qstring.sas
'data _null_;  string=symget("sysjobid");  put string;run;'&lt;/PRE&gt;
&lt;P&gt;and run it with SAS I get this LOG.&lt;/P&gt;
&lt;PRE&gt;NOTE: SAS initialization used:
      real time           0.27 seconds
      cpu time            0.03 seconds
      
1          'data _null_;  string=symget("sysjobid");  put string;run;'
           ___________________________________________________________
           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

ERROR: Errors printed on page 1.

NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
      real time           0.28 seconds
      cpu time            0.03 seconds
&lt;/PRE&gt;
&lt;P&gt;But if I make a macro variable with that value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string='data _null_;  string=symget("sysjobid");  put string;run;';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And run it through %SYSFUNC(DOSUBL()) it runs.&lt;/P&gt;
&lt;PRE&gt;174   %put BEFORE;
BEFORE























































17548
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


175   %let rc=%sysfunc(dosubl(&amp;amp;string));
176   %put &amp;amp;=rc;
RC=0
177   %put AFTER;
AFTER
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2019 15:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561622#M157260</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-26T15:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561647#M157266</link>
      <description>&lt;P&gt;The way I see it:&lt;/P&gt;
&lt;P&gt;Function DOSUBL does a lot behind the scenes and is not at all a regular function.&lt;BR /&gt;It starts a new SAS thread and passes code to that thread. &lt;BR /&gt;It looks that, as part of the code-passing, surrounding single quotes are removed.&lt;BR /&gt;This could be considered a feature or a bug.&lt;BR /&gt;Note that surrounding double quotes are not removed.&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 00:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561647#M157266</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-27T00:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561675#M157283</link>
      <description>&lt;P&gt;It's not only when called via a macro that the surrounding single quotes are removed.&lt;/P&gt;
&lt;P&gt;This runs fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  RC=dosubl("  'data _null_;  string=symget(""sysjobid"");  put string;run;'  ");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[Edit: This code does NOT run as expected.]&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 21:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561675#M157283</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-27T21:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561681#M157288</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Interesting. When I run your code, id doesn't run&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: SAS initialization used:
      real time           4.01 seconds
      cpu time            1.17 seconds

1    data _null_;
2      RC=dosubl("  'data _null_;  string=symget(""sysjobid"");  put string;run;'  ");
3    run;

ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: DATA statement used (Total process time):
      real time           0.67 seconds
      cpu time            0.18 seconds
&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 May 2019 07:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561681#M157288</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-05-27T07:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561798#M157323</link>
      <description>&lt;P&gt;Mmmm. You are right. I did a few tests and got confused on the way. This code does generate an error.&lt;/P&gt;
&lt;P&gt;Apologies for wasting your time.&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 21:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561798#M157323</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-27T21:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561878#M157357</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Far from wasting my time, I had a very interesting evening experimenting with dosubl. I was aware of it from "What's new in SAS x.x.x", but have never used it. So it is like when I got a Dremel as a birthday present many years back. I had never missed it before, but now I'm on my third.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I got confused on the way too, I have some examples here. It makes sense that both 1.2 and 1.3 works, but why does 2.2 not work, when 2.3 does? - Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;******* without surrounding quotes *******;
%let cmd = %str(data _null_;  string=symget("sysjobid");  put string; run;);

* 1.1 - works;
%let rc = %sysfunc(dosubl(&amp;amp;cmd));

* 1.2 - works;
data _null_;
	cmd = symget('cmd');
	put cmd;
	RC = dosubl(cmd);
run;

* 1.3 - works;
data _null_;
	cmd = 'data _null_;  string=symget("sysjobid");  put string; run;';
	put cmd;
	RC = dosubl(cmd);
run;

******* with surrounding quotes ********;
%let cmd = %str('data _null_;  string=symget("sysjobid");  put string; run;');

* 2.1 - works;
%let rc = %sysfunc(dosubl(&amp;amp;cmd));

* 2.2 - DOES NOT WORK;
data _null_;
	cmd = symget('cmd');
	put cmd;
	RC = dosubl(cmd);
run;

* 2.3  - works;
data _null_;
	cmd = "'" || 'data _null_;  string=symget("sysjobid");  put string; run;' || "'";
	put cmd;
	RC = dosubl(cmd);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 09:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561878#M157357</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-05-28T09:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561906#M157366</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It makes sense that both 1.2 and 1.3 works, but why does 2.2 not work, when 2.3 does? - Any ideas?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good question. It seems that DOSUBL doesn't like the trailing blanks after the closing single quote in CMD (character variable of length 200) in 2.2, which are not present in 2.3 where CMD is a variable of length 60. As it turns out, it doesn't like &lt;EM&gt;leading&lt;/EM&gt; blanks before the opening single quote either:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* 2.4 - DOES NOT WORK;
%let cmd1 = %str( 'data _null_;  string=symget("sysjobid");  put string; run;');
%let cmd2 = %str('data _null_;  string=symget("sysjobid");  put string; run;' );
%let rc = %sysfunc(dosubl(&amp;amp;cmd1));
%let rc = %sysfunc(dosubl(&amp;amp;cmd2));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 May 2019 10:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/561906#M157366</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-28T10:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/562123#M157442</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; It seems that DOSUBL doesn't like the trailing blanks [...]&amp;nbsp;it doesn't like&amp;nbsp;leading&amp;nbsp;blanks before the opening single quote either&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Ah! That explains it! I added the spaces in my code after pasting&amp;nbsp;it here, to making it more legible.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;This runs:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  RC=dosubl("'data _null_;  string=symget(""sysjobid"");  put string;run;'");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 22:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/562123#M157442</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-28T22:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %SYSFUNC(DOSUBL() remove outer quotes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/562124#M157443</link>
      <description>&lt;P&gt;In light of the comments by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;,&amp;nbsp;this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* 2.2 - DOES NOT WORK;
data _null_;
	cmd = symget('cmd');
	put cmd;
	RC = dosubl(cmd);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can run like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* 2.2 - DOES WORK;
data _null_;
	cmd = symget('cmd');
	put cmd;
	RC = dosubl(trim(cmd));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 22:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-SYSFUNC-DOSUBL-remove-outer-quotes/m-p/562124#M157443</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-28T22:56:40Z</dc:date>
    </item>
  </channel>
</rss>

