<?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: SAS macro help to pass variable back to the calling program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97551#M20584</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at the DOSUBL function.&lt;/P&gt;&lt;P&gt;There is no way call execute can invoke code that returns a value to the data step with that call execute syntax.&lt;/P&gt;&lt;P&gt;Another way might be to create your own call routine or a user defined function with PROC FCMP. Both these and DOSUBL complete their process before the following line in the data step continues execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;good luck&lt;/P&gt;&lt;P&gt;peterC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 09 Jun 2013 07:59:53 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2013-06-09T07:59:53Z</dc:date>
    <item>
      <title>SAS macro help to pass variable back to the calling program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97546#M20579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to get a macro to work that will send in a variable in order to read a database, and then return the variable it reads off the database.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro works correctly, as I can see from the proc print showing the db read worked.&amp;nbsp; But how to I pluck the variable value it reads from working memory and return it to the calling program?&amp;nbsp; These are 2 completely separate pieces of code - the macro is not within the main module of code, it is a separate file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Calling module:&lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" id="yui_3_7_2_1_1370382585533_7033" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&amp;nbsp; format passvar1 $3.;&lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" id="yui_3_7_2_1_1370382585533_7040" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&amp;nbsp; passvar1=substr(some_other_variable,1,2);&lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" id="yui_3_7_2_1_1370382585533_7041" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&amp;nbsp; &lt;SPAN style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;call execute('%mymacro('||passvar1||')'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; Var_i_want_populated = the value that was read in the mymacro macro; &lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" id="yui_3_7_2_1_1370382585533_7046" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" id="yui_3_7_2_1_1370382585533_7047" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;Macro:&lt;/P&gt;&lt;P class="yiv4791185006MsoNormal" style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;call symput('random_var_name',put(var_that_was_read_from_the_database));&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;var_that_was_read_from_the_database DOES have a value in it and I want to return it to the calling module so that I can assign its value to Var_i_want_populated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;Does anyone know how to do this?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 11:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97546#M20579</guid>
      <dc:creator>pheynix</dc:creator>
      <dc:date>2013-06-06T11:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro help to pass variable back to the calling program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97547#M20580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will need to show us the macro definition and eventually an execution log in order to give you advice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just as a thought: You could have a timing problem here:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="shortDesc"&gt;Call execute "Resolves the argument, and issues the resolved value for execution&lt;/SPAN&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt; at the next step boundary&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN class="shortDesc"&gt;."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="shortDesc"&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543697.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543697.htm"&gt;SAS(R) 9.2 Macro Language: Reference&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="shortDesc"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="shortDesc"&gt;It doesn't matter that your code is stored in separate .sas files. It still will be executed together within the same environment.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 11:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97547#M20580</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-06-06T11:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro help to pass variable back to the calling program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97548#M20581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you could know the macro variable name which holds the value in the macro(a separate file).&amp;nbsp; You can do in these 3 ways&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Define the Macro variable&amp;nbsp; as &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;GLOBAL&lt;/STRONG&gt;&lt;/SPAN&gt; which holds the results and if done this value can be used in the calling program.&lt;/P&gt;&lt;P&gt;2. If you are aware of the name of macro variable then you can get the value by fetching the value from &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;sashelp.vtable&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3. This one is weird. Create a additional parameter in the Macro which holds the results and use it in the calling.&lt;/P&gt;&lt;P&gt;Ex: &lt;/P&gt;&lt;P&gt;%local input result;&lt;/P&gt;&lt;P&gt;%mymacro(inp=&amp;amp;input,&lt;/P&gt;&lt;P&gt;&amp;nbsp; res=result);&lt;/P&gt;&lt;P&gt;%put Result = &amp;amp;result; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if this answers your question.....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 11:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97548#M20581</guid>
      <dc:creator>suraestar</dc:creator>
      <dc:date>2013-06-06T11:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro help to pass variable back to the calling program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97549#M20582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was exactly what I was thinking as well. Have you tried assigning the value in a new data step. I am also assuming that your variable assignment code is actually something similar to:&lt;/P&gt;&lt;P&gt;var_I_want_populated = "&amp;amp;random_var_name" ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EJ&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 11:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97549#M20582</guid>
      <dc:creator>esjackso</dc:creator>
      <dc:date>2013-06-06T11:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro help to pass variable back to the calling program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97550#M20583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This might be a simple case of using the &lt;SPAN style="font-family: 'courier new', courier;"&gt;%global&lt;/SPAN&gt; macro statement, but I'm not sure I fully understand the situation, e.g:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does mymacro invoke some SQL?&lt;/P&gt;&lt;P&gt;Does mymacro create a table / dataset of results?&lt;/P&gt;&lt;P&gt;Can mymacro be changed to use "&lt;SPAN style="color: #454545; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;call symput('random_var_name',put(var_that_was_read_from_the_database)); &lt;/SPAN&gt;" as part of a data step?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May be the above can be all answered if you share the code for mymacro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 11:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97550#M20583</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-06-06T11:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro help to pass variable back to the calling program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97551#M20584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at the DOSUBL function.&lt;/P&gt;&lt;P&gt;There is no way call execute can invoke code that returns a value to the data step with that call execute syntax.&lt;/P&gt;&lt;P&gt;Another way might be to create your own call routine or a user defined function with PROC FCMP. Both these and DOSUBL complete their process before the following line in the data step continues execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;good luck&lt;/P&gt;&lt;P&gt;peterC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Jun 2013 07:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-help-to-pass-variable-back-to-the-calling-program/m-p/97551#M20584</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-06-09T07:59:53Z</dc:date>
    </item>
  </channel>
</rss>

