<?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 Function style macros in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22525#M3978</link>
    <description>Dear all,&lt;BR /&gt;
&lt;BR /&gt;
I would like to learn how to create function style macros, i.e, macros which returns some value.&lt;BR /&gt;
&lt;BR /&gt;
Could somebody recommend me any documentation.&lt;BR /&gt;
&lt;BR /&gt;
I am using this kind of macros but sometimes my function doesn't work and I do not understand why.&lt;BR /&gt;
&lt;BR /&gt;
For example:&lt;BR /&gt;
&lt;BR /&gt;
%macro t1();&lt;BR /&gt;
%if &amp;amp;t1&amp;gt;0 %then %do; &lt;BR /&gt;
  %let t1 = %eval(&amp;amp;t1+1);&lt;BR /&gt;
  %let t2 = 0;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %let t1 = 1;&lt;BR /&gt;
&amp;amp;t1.&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%let t1=0;&lt;BR /&gt;
&lt;BR /&gt;
%put %t1;&lt;BR /&gt;
%put %t1;&lt;BR /&gt;
&lt;BR /&gt;
IT WORKS BUT,&lt;BR /&gt;
&lt;BR /&gt;
%macro maxcol(in,var);&lt;BR /&gt;
local max;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select max(&amp;amp;var) into :max&lt;BR /&gt;
from &amp;amp;in;&lt;BR /&gt;
quit;&lt;BR /&gt;
&amp;amp;max.&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
IT DOESN'T WORK.&lt;BR /&gt;
&lt;BR /&gt;
Perhaps, I can't use non macro sentences in this kind of macros?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help!!&lt;BR /&gt;
Juan Vte.</description>
    <pubDate>Mon, 02 Jun 2008 15:16:35 GMT</pubDate>
    <dc:creator>JuanVte</dc:creator>
    <dc:date>2008-06-02T15:16:35Z</dc:date>
    <item>
      <title>Function style macros</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22525#M3978</link>
      <description>Dear all,&lt;BR /&gt;
&lt;BR /&gt;
I would like to learn how to create function style macros, i.e, macros which returns some value.&lt;BR /&gt;
&lt;BR /&gt;
Could somebody recommend me any documentation.&lt;BR /&gt;
&lt;BR /&gt;
I am using this kind of macros but sometimes my function doesn't work and I do not understand why.&lt;BR /&gt;
&lt;BR /&gt;
For example:&lt;BR /&gt;
&lt;BR /&gt;
%macro t1();&lt;BR /&gt;
%if &amp;amp;t1&amp;gt;0 %then %do; &lt;BR /&gt;
  %let t1 = %eval(&amp;amp;t1+1);&lt;BR /&gt;
  %let t2 = 0;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %let t1 = 1;&lt;BR /&gt;
&amp;amp;t1.&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%let t1=0;&lt;BR /&gt;
&lt;BR /&gt;
%put %t1;&lt;BR /&gt;
%put %t1;&lt;BR /&gt;
&lt;BR /&gt;
IT WORKS BUT,&lt;BR /&gt;
&lt;BR /&gt;
%macro maxcol(in,var);&lt;BR /&gt;
local max;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select max(&amp;amp;var) into :max&lt;BR /&gt;
from &amp;amp;in;&lt;BR /&gt;
quit;&lt;BR /&gt;
&amp;amp;max.&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
IT DOESN'T WORK.&lt;BR /&gt;
&lt;BR /&gt;
Perhaps, I can't use non macro sentences in this kind of macros?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help!!&lt;BR /&gt;
Juan Vte.</description>
      <pubDate>Mon, 02 Jun 2008 15:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22525#M3978</guid>
      <dc:creator>JuanVte</dc:creator>
      <dc:date>2008-06-02T15:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Function style macros</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22526#M3979</link>
      <description>Juan&lt;BR /&gt;
this is working&lt;BR /&gt;
you forget a  %  before local&lt;BR /&gt;
but from a point of view of sas code generate &lt;BR /&gt;
the value generated is outside any sas context&lt;BR /&gt;
and rejected by the processor&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro maxcol(in,var);&lt;BR /&gt;
%local max;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select max(&amp;amp;var) into :max&lt;BR /&gt;
from &amp;amp;in;&lt;BR /&gt;
quit;&lt;BR /&gt;
&amp;amp;max.&lt;BR /&gt;
%mend;&lt;BR /&gt;
%maxcol(sashelp.class,age)&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 02 Jun 2008 15:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22526#M3979</guid>
      <dc:creator>Andre</dc:creator>
      <dc:date>2008-06-02T15:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Function style macros</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22527#M3980</link>
      <description>Thank you Andre,&lt;BR /&gt;
&lt;BR /&gt;
you are right.&lt;BR /&gt;
&lt;BR /&gt;
But my real problem is about the second point, as you noted, this is outside any sas context!&lt;BR /&gt;
&lt;BR /&gt;
For %t1 sas undertands perfectly what I want but not for %maxcol.&lt;BR /&gt;
&lt;BR /&gt;
I would like to use this macro in sentences as for example:&lt;BR /&gt;
&lt;BR /&gt;
%put %maxcol(sashelp.class,age);&lt;BR /&gt;
&lt;BR /&gt;
or &lt;BR /&gt;
&lt;BR /&gt;
if %maxcol(sashelp.class,age) &amp;gt; 0 then ...;&lt;BR /&gt;
&lt;BR /&gt;
I can use %t1 but not with %maxcol in the above sentences. For that, I am thinking that I miss something else&lt;BR /&gt;
&lt;BR /&gt;
What do you think?</description>
      <pubDate>Mon, 02 Jun 2008 16:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22527#M3980</guid>
      <dc:creator>JuanVte</dc:creator>
      <dc:date>2008-06-02T16:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Function style macros</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22528#M3981</link>
      <description>there must be other ways to obtain the information you need from a "function-style" macro because between the &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; and &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; of a statement using your "function-style" macro like [pre]   &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; %maxcol( some.data_set )  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; [/pre] your macro cannot generate any semi-colons, and certainly not a step, without interrupting the statement in which %maxcol() is used.&lt;BR /&gt;
Without generating semi-colons, there are ways to obtain for example: &lt;BR /&gt;
* the NOBS of a SAS data set ~ from sashelp.vtable  &lt;BR /&gt;
* the maximum value of a variable in a dataset &lt;BR /&gt;
If the macro must use open() fetch() and other functions, they must be called within a %sysfunc() "environment", not as plain base SAS syntax like proc contents data= &amp;amp;syslast out= _data_ noprint; run; &lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;A function-style macro must generate only macro language statements,  because everything else is the result returned by your macro.&lt;/B&gt; &lt;BR /&gt;
&lt;BR /&gt;
You will need to recognise and understand the semi-colons that are part of your macro language statements and those which are generated.&lt;BR /&gt;
The semi-colon of a %let statement is macro language. &lt;BR /&gt;
In the macro statement [pre]   %if &amp;amp;A eq &amp;amp;B %then %do ;&lt;BR /&gt;
          A&lt;BR /&gt;
   %end ;[/pre] no semi colons are generated. However this will generate four semi-colons[pre]   %if not %sysfunc( exist( &amp;amp;ds )) %then %do ;&lt;BR /&gt;
      data _null_ ; file print ; put  "no data in &amp;amp;ds"; run;&lt;BR /&gt;
   %end ;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Hope this helps clarify what a "function-style" macro needs, and why your proposal could not work.&lt;BR /&gt;
 &lt;BR /&gt;
Good Luck&lt;BR /&gt;
&lt;BR /&gt;
PeterC

Message was edited by: Peter.C</description>
      <pubDate>Mon, 02 Jun 2008 19:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22528#M3981</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2008-06-02T19:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Function style macros</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22529#M3982</link>
      <description>Thanks for your clear comments Peter!&lt;BR /&gt;
&lt;BR /&gt;
I'll think about how to do it without semicolons and I will come back to this post &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Tue, 03 Jun 2008 10:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Function-style-macros/m-p/22529#M3982</guid>
      <dc:creator>JuanVte</dc:creator>
      <dc:date>2008-06-03T10:10:46Z</dc:date>
    </item>
  </channel>
</rss>

