<?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: execute macro in data step with json string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/execute-macro-in-data-step-with-json-string/m-p/679863#M205342</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I am attempting to execute a macro from inside a data step.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Actually you are trying to use a data step to use CALL EXECUTE to stack calls to a macro to execute after the data step has finished.&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;It is building the execution string as I would expect until I get to the part of needing to provide a JSON string to the final parameter.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Please provide example input values of the dataset variables:&amp;nbsp;jsonstr&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please proved example of a working call to the macro for that value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your macro does not appear to have been defined, so even once you get the call syntax fixed you still need to figure out how to get the macro compiled.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You might also explain how the macro is going to use that input.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Try something like this so that the macro call and the %BQUOTE() call are pushed onto the stack to run after the data step instead of execution while the CALL EXECUTE statement is running.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&amp;amp;listID,logpath=&amp;amp;logpath,token=&amp;amp;q_token'
,',contacts=%nrstr(%BQUOTE(',jsonstr,'))'
,')'
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt; It could be that easiest thing to do is just put the value of JSONSTR inside of single quotes so that the macro processor will ignore any &amp;amp; or % characters in the string.&amp;nbsp; But we would need to see how that value is used in the macro body.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&amp;amp;listID,logpath=&amp;amp;logpath,token=&amp;amp;q_token'
,',contacts=',quote(trim(jsonstr),"'")
,')'
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Aug 2020 18:38:34 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-08-27T18:38:34Z</dc:date>
    <item>
      <title>execute macro in data step with json string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-macro-in-data-step-with-json-string/m-p/679855#M205339</link>
      <description>&lt;P&gt;I am attempting to execute a macro from inside a data step. It is building the execution string as I would expect until I get to the part of needing to provide a JSON string to the final parameter.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let execstr="listID=&amp;amp;listID,logpath=&amp;amp;logpath,token=&amp;amp;q_token,contacts=";
%put &amp;amp;=execstr;
data cconts;
	set work.qcontacts;
	call execute('%qualtrics_createcontacts('||&amp;amp;execstr||%nrstr('%BQUOTE%(')||jsonstr||%nrstr('%)%)'));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The results of this in the log show that BQUOTE is not included, the closing paren is not included. I am not sure how to finish it off. Here is the log results so you understand what I mean.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;WARNING: Apparent invocation of macro QUALTRICS_CREATECONTACTS not resolved.
 WARNING: Apparent invocation of macro QUALTRICS_CREATECONTACTS not resolved.
 NOTE: Line generated by the CALL EXECUTE routine.
 1         + %qualtrics_createcontacts(listID=ML_5c3kFhBxk2MvSfP,logpath=/dcri/cdm/DEV/Qualtrics,token=rCjSeE0WKHIMwaTzC7GA7BKhJRW9Rs
             _
             180
 1        !+opxxEGRqFK,contacts={"firstName":"198242","lastName":"103","extRef":"118415"}
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 
 2         +
 3         +                       %)%)
 4         + 
 %qualtrics_createcontacts(listID=ML_5c3kFhBxk2MvSfP,logpath=/dcri/cdm/DEV/Qualtrics,token=rCjSeE0WKHIMwaTzC7GA7BKhJRW9RsopxxEGRqFK,c
 ontacts={"firstName":"198243","lastName":"103","extRef":"118414"}&lt;/LI-CODE&gt;&lt;P&gt;How do I get the closing parenthesis in there? How do I make sure the jsonstr portion is handled and passed correctly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 18:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-macro-in-data-step-with-json-string/m-p/679855#M205339</guid>
      <dc:creator>evaleah</dc:creator>
      <dc:date>2020-08-27T18:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: execute macro in data step with json string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-macro-in-data-step-with-json-string/m-p/679863#M205342</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I am attempting to execute a macro from inside a data step.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Actually you are trying to use a data step to use CALL EXECUTE to stack calls to a macro to execute after the data step has finished.&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;It is building the execution string as I would expect until I get to the part of needing to provide a JSON string to the final parameter.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Please provide example input values of the dataset variables:&amp;nbsp;jsonstr&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please proved example of a working call to the macro for that value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your macro does not appear to have been defined, so even once you get the call syntax fixed you still need to figure out how to get the macro compiled.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You might also explain how the macro is going to use that input.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Try something like this so that the macro call and the %BQUOTE() call are pushed onto the stack to run after the data step instead of execution while the CALL EXECUTE statement is running.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&amp;amp;listID,logpath=&amp;amp;logpath,token=&amp;amp;q_token'
,',contacts=%nrstr(%BQUOTE(',jsonstr,'))'
,')'
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt; It could be that easiest thing to do is just put the value of JSONSTR inside of single quotes so that the macro processor will ignore any &amp;amp; or % characters in the string.&amp;nbsp; But we would need to see how that value is used in the macro body.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats
('%nrstr(%qualtrics_createcontacts)'
,'(listID=&amp;amp;listID,logpath=&amp;amp;logpath,token=&amp;amp;q_token'
,',contacts=',quote(trim(jsonstr),"'")
,')'
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 18:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-macro-in-data-step-with-json-string/m-p/679863#M205342</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-27T18:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: execute macro in data step with json string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-macro-in-data-step-with-json-string/m-p/679907#M205368</link>
      <description>Thank you so much. The bit I needed was the suggestion of just adding single quote marks. I have no idea why I didn't think of that before.&lt;BR /&gt;My issue was not how the macro was processing the string. The issue was it wouldn't call the macro at all! The single quote mark around the json string was the magic I was missing.</description>
      <pubDate>Thu, 27 Aug 2020 21:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-macro-in-data-step-with-json-string/m-p/679907#M205368</guid>
      <dc:creator>evaleah</dc:creator>
      <dc:date>2020-08-27T21:23:31Z</dc:date>
    </item>
  </channel>
</rss>

