<?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 Error when trying to return a value from SAS Macro Function after using a data step. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103357#M21572</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've built a macro that will merge the values of a data set and create a new data set with an updated name. I'm trying to return the name in the macro, but it is throwing a couple errors. &lt;/P&gt;&lt;P&gt;The errors occur on the merge statement and on the last return statement. I'm not sure why since if I remove the return statement everything works. But, the second I add it in, these two errors reappear. Any suggestions would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Build Data */&lt;/P&gt;&lt;P&gt;data scores;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="codeFocus" style="background-color: #dcdcdc;"&gt;input Name $ Test_1 Test_2 Test_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Bill 187 97 103&lt;/P&gt;&lt;P&gt;Carlos 156 76 74&lt;/P&gt;&lt;P&gt;Monique 99 102 129&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data scores_post;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="codeFocus" style="background-color: #dcdcdc;"&gt;input Name $ Test_1 Test_2 Test_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Bill 23 14 61&lt;/P&gt;&lt;P&gt;Carlos 51 23 44&lt;/P&gt;&lt;P&gt;Monique 13 812 43&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let num = 0; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro update_info(old,new);&lt;/P&gt;&lt;P&gt;%global num;&lt;/P&gt;&lt;P&gt;%let num = %eval(&amp;amp;num.+1);&lt;/P&gt;&lt;P&gt;%let new_name = &amp;amp;new._&amp;amp;num.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Update information */&lt;/P&gt;&lt;P&gt;data &amp;amp;new_name.;&lt;/P&gt;&lt;P&gt;merge &amp;amp;old. &amp;amp;new.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Return new dataset name */&lt;/P&gt;&lt;P&gt;&amp;amp;new_name.&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let catch = %update_info(scores,scores_post);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Jun 2013 02:16:50 GMT</pubDate>
    <dc:creator>Cboath</dc:creator>
    <dc:date>2013-06-12T02:16:50Z</dc:date>
    <item>
      <title>Error when trying to return a value from SAS Macro Function after using a data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103357#M21572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've built a macro that will merge the values of a data set and create a new data set with an updated name. I'm trying to return the name in the macro, but it is throwing a couple errors. &lt;/P&gt;&lt;P&gt;The errors occur on the merge statement and on the last return statement. I'm not sure why since if I remove the return statement everything works. But, the second I add it in, these two errors reappear. Any suggestions would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Build Data */&lt;/P&gt;&lt;P&gt;data scores;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="codeFocus" style="background-color: #dcdcdc;"&gt;input Name $ Test_1 Test_2 Test_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Bill 187 97 103&lt;/P&gt;&lt;P&gt;Carlos 156 76 74&lt;/P&gt;&lt;P&gt;Monique 99 102 129&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data scores_post;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="codeFocus" style="background-color: #dcdcdc;"&gt;input Name $ Test_1 Test_2 Test_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Bill 23 14 61&lt;/P&gt;&lt;P&gt;Carlos 51 23 44&lt;/P&gt;&lt;P&gt;Monique 13 812 43&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let num = 0; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro update_info(old,new);&lt;/P&gt;&lt;P&gt;%global num;&lt;/P&gt;&lt;P&gt;%let num = %eval(&amp;amp;num.+1);&lt;/P&gt;&lt;P&gt;%let new_name = &amp;amp;new._&amp;amp;num.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Update information */&lt;/P&gt;&lt;P&gt;data &amp;amp;new_name.;&lt;/P&gt;&lt;P&gt;merge &amp;amp;old. &amp;amp;new.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Return new dataset name */&lt;/P&gt;&lt;P&gt;&amp;amp;new_name.&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let catch = %update_info(scores,scores_post);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 02:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103357#M21572</guid>
      <dc:creator>Cboath</dc:creator>
      <dc:date>2013-06-12T02:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Error when trying to return a value from SAS Macro Function after using a data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103358#M21573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure if you can return values in this manner, at the same time as the macro is submitting code.&lt;/P&gt;&lt;P&gt;Either way, why don you just declare new_name as %global?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 07:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103358#M21573</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-06-12T07:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Error when trying to return a value from SAS Macro Function after using a data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103359#M21574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are allowed to return values in this manner. Take for example this macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;macro isWeekend(date);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if date=&amp;nbsp; %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let date = %sysfunc(today());&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let week_day = %sysfunc(weekday(&amp;amp;date.)); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;wd.=1 or &amp;amp;wd.=7 %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let &lt;SPAN style="color: #333333; font-family: 'Courier New', Courier, monospace; background-color: #ffffff;"&gt;is_it_the_weekend&lt;/SPAN&gt; = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let &lt;SPAN style="color: #333333; font-family: 'Courier New', Courier, monospace; background-color: #ffffff;"&gt;is_it_the_weekend = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;&lt;SPAN style="color: #333333; font-family: 'Courier New', Courier, monospace; background-color: #ffffff;"&gt;is_it_the_weekend&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;Calling would be like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;"&gt;%put %isWeekend(&lt;SPAN style="color: #333333; font-family: 'Courier New', Courier, monospace; background-color: #ffffff;"&gt;%sysfunc(today())&lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should return either a 0 or 1 and can be used in future macros for specific calendar pulls, et cetera.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason why I do not want to declare a global variable is because then this code and code like this will lose the ability to be easily picked up and placed in other projects without an issue with context. The ability to return a value is critical.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 01:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103359#M21574</guid>
      <dc:creator>Cboath</dc:creator>
      <dc:date>2013-06-13T01:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error when trying to return a value from SAS Macro Function after using a data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103360#M21575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since your macro is generating actual SAS code that you want to execute you cannot "return" a value by making it the generated code.&amp;nbsp; Instead you must return the value in a macro variable or a dataset.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To make it flexible pass the NAME of the macro variable as a parameter.&amp;nbsp; You can specify default values for the new parameters in the macro definition if you want.&amp;nbsp; You can even create a new GLOBAL macro variable when the requested macro variable does not already exist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro update_info(old,new,new_name=catch,counter=num);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if not %symexist(&amp;amp;counter) %then %global &amp;amp;counter;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if not %symexist(&amp;amp;new_name) %then %global &amp;amp;new_name;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let &amp;amp;counter = %eval(&amp;amp;&amp;amp;&amp;amp;counter + 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let &amp;amp;new_name = &amp;amp;new._&amp;amp;&amp;amp;&amp;amp;counter ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;/* Update information */&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data &amp;amp;&amp;amp;&amp;amp;new_name ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; merge &amp;amp;old &amp;amp;new ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 10pt; line-height: 1.5em;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%let num = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let catch= ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%update_info(scores,scores_post,new_name=catch,counter=num);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 01:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103360#M21575</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-13T01:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Error when trying to return a value from SAS Macro Function after using a data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103361#M21576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Remember that SAS macro is not a "language" it is just a macro.&amp;nbsp; That is a utility to facility the generation of text.&lt;/P&gt;&lt;P&gt;Your example works because you are capturing ALL of the generated text.&amp;nbsp; Other than the 0 or 1 that macro does not generate any code that macro needs to pass to SAS to execute.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 01:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103361#M21576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-13T01:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Error when trying to return a value from SAS Macro Function after using a data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103362#M21577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't bother to return the name as SAS is already doing that for you in the SYSLAST automatic macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%update_info(scores,scores_post);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let catch=&amp;amp;syslast ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 01:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-when-trying-to-return-a-value-from-SAS-Macro-Function/m-p/103362#M21577</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-13T01:52:05Z</dc:date>
    </item>
  </channel>
</rss>

