<?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 Help with user defined function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487666#M127091</link>
    <description>&lt;P&gt;I am learning SAS. I tested a function shown below, the function is to find the larger value of two integers. However, it kept reporting errors shown below. Could someone please help me with that? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro max(dat);
data _null_;
set &amp;amp;dat;
if x &amp;gt;= y then put x =;
else put y =;
%mend max;

data temp;
input x y;
cards;
7 3
;
run;

proc print data=temp;
run;

%max(temp);&lt;/PRE&gt;&lt;PRE&gt;2633  %max(temp);
NOTE: Line generated by the invoked macro "MAX".
1       data _null_; set &amp;amp;dat; if x &amp;gt;= y then put x =; else put y =;
                         -
                         22
                         200
ERROR: File WORK.DAT.DATA does not exist.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS,
              END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Aug 2018 08:35:17 GMT</pubDate>
    <dc:creator>LuRo</dc:creator>
    <dc:date>2018-08-17T08:35:17Z</dc:date>
    <item>
      <title>Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487666#M127091</link>
      <description>&lt;P&gt;I am learning SAS. I tested a function shown below, the function is to find the larger value of two integers. However, it kept reporting errors shown below. Could someone please help me with that? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro max(dat);
data _null_;
set &amp;amp;dat;
if x &amp;gt;= y then put x =;
else put y =;
%mend max;

data temp;
input x y;
cards;
7 3
;
run;

proc print data=temp;
run;

%max(temp);&lt;/PRE&gt;&lt;PRE&gt;2633  %max(temp);
NOTE: Line generated by the invoked macro "MAX".
1       data _null_; set &amp;amp;dat; if x &amp;gt;= y then put x =; else put y =;
                         -
                         22
                         200
ERROR: File WORK.DAT.DATA does not exist.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS,
              END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 08:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487666#M127091</guid>
      <dc:creator>LuRo</dc:creator>
      <dc:date>2018-08-17T08:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487671#M127092</link>
      <description>&lt;P&gt;A "run" is missing at the end of the data step in the macro. Other than that, i don't see any problem with your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;20   %macro max(dat);
21   data _null_;
22   set &amp;amp;dat;
23   if x &amp;gt;= y then put x =;
24   else put y =;
25   run;
26   %mend max;
27
28   data temp;
29   input x y;
30   cards;

NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


32   ;
33   run;
34
35   proc print data=temp;
36   run;

NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.07 seconds
      cpu time            0.00 seconds


37
38   %max(temp);

x=7
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 08:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487671#M127092</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-08-17T08:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487674#M127093</link>
      <description>&lt;P&gt;You must have some other code running or code has hung over.&amp;nbsp; Start a new session as the code runs fine for me in a new session.&amp;nbsp; Also couple of bits of advice:&lt;/P&gt;
&lt;PRE&gt;%macro max(dat);
  data _null_;
    set &amp;amp;dat.;
    if x &amp;gt;= y then put x =;
    else put y =;
  run;
%mend max;

data temp;
  input x y;
cards;
7 3
;
run;

%max(temp);&lt;/PRE&gt;
&lt;P&gt;Always finish macro variables with a dot - a lot of the time you will get away with it, but sometimes you will not, therefore good practive to always do it.&lt;/P&gt;
&lt;P&gt;Always finish steps, in this case the run; was missing in the macro.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Indent code to make it readable.&lt;/P&gt;
&lt;P&gt;Lastly and most important, I know this one is for learning, but knowing when macro adds anything to the code is a key skill.&amp;nbsp; It is often misused.&amp;nbsp; Try to do everything in Base SAS (datastep or proc), then when you see a benefit to macro'tizing the code (e.g. for a global tool) then put the effort in to do proper SDLC on it.&amp;nbsp; The worst code out there is undocumented, obfuscated macro heavy code.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 08:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487674#M127093</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-17T08:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487675#M127094</link>
      <description>&lt;P&gt;Very strange. When I submit your code, there is no problem (except that you miss the final RUN statement, so that nothing happens). Are you sure that you did not submit "set &amp;amp; dat" or something like that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 08:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487675#M127094</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-08-17T08:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487738#M127108</link>
      <description>Thanks a lot for the detailed reply. The problem was solved by starting a&lt;BR /&gt;new session.&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Aug 2018 12:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487738#M127108</guid>
      <dc:creator>LuRo</dc:creator>
      <dc:date>2018-08-17T12:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487740#M127109</link>
      <description>Thanks a lot for the reply. The bug was fixed by restarting SAS.</description>
      <pubDate>Fri, 17 Aug 2018 12:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487740#M127109</guid>
      <dc:creator>LuRo</dc:creator>
      <dc:date>2018-08-17T12:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487742#M127110</link>
      <description>&lt;P&gt;No probs.&amp;nbsp; For future note, things can get stuck in the SAS compiler.&amp;nbsp; The reason is that SAS interprets step by step, so if there is unbalanced quotes - one problem which often comes up, then until that is closed with another quote, then anything submitted from there on is just plain text until the quote is ended.&amp;nbsp; If you have oddities in your code like this, its usually simpler to start a new session.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 12:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487742#M127110</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-17T12:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487744#M127111</link>
      <description>Thanks a lot for replying. By restarting SAS the problem was solved.&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Aug 2018 12:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487744#M127111</guid>
      <dc:creator>LuRo</dc:creator>
      <dc:date>2018-08-17T12:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help with user defined function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487957#M127164</link>
      <description>&lt;P&gt;And in a more esoteric mode: SAS has a data step function called MAX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; x= 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; y= 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; z= 18;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; a= max(x,y,z);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; put a=;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not a good idea to create code with the name of an existing SAS function, especially one that behaves differently than the SAS supplied version as your code may be misinterpreted at a later date.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 21:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-user-defined-function/m-p/487957#M127164</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-17T21:40:34Z</dc:date>
    </item>
  </channel>
</rss>

