<?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: how do I recognise the returned value of a macro as a variable in Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195279#M36747</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anytime when you end up with some convoluted piece of programming, it's good to question the original intent. Complicated code often signals a wrong view of the problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Apr 2015 05:30:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2015-04-15T05:30:03Z</dc:date>
    <item>
      <title>how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195271#M36739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to use a macro to dynamically return a a text string that I would like proc sql to recognise as a variable to sum, however, it recognises as a character and fails.&amp;nbsp; any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;%macro offsetnum(variable,startdate, enddate, plus);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #800080; font-size: 10pt; font-family: Courier New;"&gt;cats(&amp;amp;variable,intck('MONTH'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;,datejul(&amp;amp;startdate),&amp;amp;enddate) + &amp;amp;plus)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;%mend; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;create table as &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;(select sum(%offsetnum("bal",startdate, enddate, 0)) as bal1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif;"&gt;I know that it resolves to "bal x" so I need to also strip the blank (in data step i used left, but sql is a bit more fussy) but I also know that even when the space has been removed I get the "ERROR: &lt;/SPAN&gt;The SUM summary function requires a numeric argument" message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 12:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195271#M36739</guid>
      <dc:creator>to_the_point</dc:creator>
      <dc:date>2015-04-14T12:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195272#M36740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, you could put in %trim() however, your cats is in the wrong place, it needs to be around the sum:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; cats(BAL,put(sum(intck('month',STARTDATE,ENDDATE,0)),best.) as BAL1&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; HAVE;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I.e. concatenate the string in BAL, to the result of the sum of intck, put to a text string.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 12:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195272#M36740</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-04-14T12:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195273#M36741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Keep in mind that the SAS macro preprocessor does not make "functions" like the functions in programming languages. Macros do not have a "return value"!&lt;/P&gt;&lt;P&gt;All a macro does is write text to the execution buffer, in your case the whole cats(.....) line (just replacing the macro referencing), which then causes the ERROR in SQL (use MLOGIC and MPRINT system options to make your macro processor more "talkative", and you will see what actually happens).&lt;/P&gt;&lt;P&gt;Everything that is not a macro function/reference is written to the execution buffer "as is", in your case the &lt;STRONG&gt;cats()&lt;/STRONG&gt; call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your macro in the current form replaces its invocation with&lt;/P&gt;&lt;P&gt;cats("bal",intck('month',datejul(startdate),enddate) + 0)&lt;/P&gt;&lt;P&gt;which creates a proc sql like&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table as&lt;/P&gt;&lt;P&gt;select sum(cats("bal",intck('month',datejul(startdate),enddate) + 0)) as ball&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, during the execution of the SQL, the cats function delivers the &lt;STRONG&gt;string&lt;/STRONG&gt; balNNN (NNN being the result of the intck function + 0, converted to char), which will be undigestible for the sum() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What do you actually want to achieve?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 12:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195273#M36741</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-04-14T12:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195274#M36742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;there is a variable in the source table (i forgot to type in the sql!) called Bal1 (actually multiple) and I want SQL to sum the values of Bal1 by a group by function (also not in the example) - very sloppy - sorry.&amp;nbsp; something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table as(&lt;/P&gt;&lt;P&gt;select age, sum(bal1) as bal1&lt;/P&gt;&lt;P&gt;from tablesource&lt;/P&gt;&lt;P&gt;group by age)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the variable to sum won't always be called bal1 but I want to call it bal1, e.g. it might be bal6 = sum(bal6) as bal1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope that makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 12:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195274#M36742</guid>
      <dc:creator>to_the_point</dc:creator>
      <dc:date>2015-04-14T12:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195275#M36743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So you could put that in a macro as:&lt;/P&gt;&lt;P&gt;%macro do_something (the_number=);&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table WANT as&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select age, sum(&amp;amp;THE_NUMBER.) as bal1&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from tablesource&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by age&lt;SPAN style="line-height: 1.5em;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%mend do_something;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro do_something (the_number=bal6);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 15:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195275#M36743</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-04-14T15:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195276#M36744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried making this a two-step process?&amp;nbsp; Step 1 stores the word BAL6 as a macro variable, and Step 2 uses BAL6 in the current CREATE statement.&amp;nbsp; You'll have to work out the need to remove blanks here and there, but the idea would be along these lines:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select %offsetnum("bal", startdate, enddate, 0) into : varname;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select sum(&amp;amp;varname) as bal1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 15:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195276#M36744</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-04-14T15:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195277#M36745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;CATS returns a &lt;SPAN style="text-decoration: underline;"&gt;&lt;SPAN style="color: #575757; text-decoration: underline;"&gt;string&lt;/SPAN&gt;&lt;/SPAN&gt; which is not a numeric value. You might want to output the result of the CATS expression to a macro variable before using it in SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 17:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195277#M36745</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-04-14T17:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195278#M36746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks everyone for your thoughts and suggestions - I must apologise as I described the problem badly and further thinking has resulted in me realising that this isn't the answer to my problem anyhow!&amp;nbsp; I will make sure I think on this and if I ever come up with an answer I'll update this thread - sorry!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 19:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195278#M36746</guid>
      <dc:creator>to_the_point</dc:creator>
      <dc:date>2015-04-14T19:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: how do I recognise the returned value of a macro as a variable in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195279#M36747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anytime when you end up with some convoluted piece of programming, it's good to question the original intent. Complicated code often signals a wrong view of the problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Apr 2015 05:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-recognise-the-returned-value-of-a-macro-as-a-variable/m-p/195279#M36747</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-04-15T05:30:03Z</dc:date>
    </item>
  </channel>
</rss>

