<?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 MACRO in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807291#M318257</link>
    <description>&lt;P&gt;&amp;nbsp;Would like to know what does 'if not(closed))' means in here?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%MACRO CLOSED;
    CLOSED=0;
    IF AC_ACCOUNT_STATUS IN ("C","W","BW") OR (AC_CLOSED_DATE NOT IN (-21914,.)) OR BK_FLAG=1 THEN Closed = 1;
%mend

%macro OPEN_TRD;
OPEN_TRD=0;
IF (NOT(CLOSED)) THEN OPEN_TRD=1;
%MEND;
&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Apr 2022 06:58:38 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2022-04-12T06:58:38Z</dc:date>
    <item>
      <title>MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807291#M318257</link>
      <description>&lt;P&gt;&amp;nbsp;Would like to know what does 'if not(closed))' means in here?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%MACRO CLOSED;
    CLOSED=0;
    IF AC_ACCOUNT_STATUS IN ("C","W","BW") OR (AC_CLOSED_DATE NOT IN (-21914,.)) OR BK_FLAG=1 THEN Closed = 1;
%mend

%macro OPEN_TRD;
OPEN_TRD=0;
IF (NOT(CLOSED)) THEN OPEN_TRD=1;
%MEND;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2022 06:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807291#M318257</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-12T06:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807295#M318260</link>
      <description>&lt;P&gt;This looks like normal data step statments, that happen to be encapsulated into macros.&lt;/P&gt;
&lt;P&gt;This is a boolean logic, so if closed is equal to 0, it's evaluated as true, otherwise false.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807295#M318260</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-04-12T07:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807297#M318261</link>
      <description>&lt;P&gt;Your macros create code that creates Boolean values, so you can use simpler logic:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro closed;
closed = (ac_account_status in ("C","W","BW") or ac_closed_date not in ('01jan1900'd,.) or bk_flag = 1);
%mend;

%macro open_trd;
open_trd = not closed;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For better readability, I replaced the numerical date value with a human-readable literal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807297#M318261</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-12T07:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807299#M318262</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the following things come to my mind.&lt;/P&gt;
&lt;P&gt;Both Macros seem to be developed in the way that they can be called within a data step, since this line for example&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF AC_ACCOUNT_STATUS IN ("C","W","BW") OR (AC_CLOSED_DATE NOT IN (-21914,.)) OR BK_FLAG=1 THEN Closed = 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not macro langage condition that is expressed, since "IF" and "THEN" are not preceded by a "%" sign.&lt;BR /&gt;Therefore I concluded, that it must be a data step condition. As a consequence, these two lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPEN_TRD=0;
IF (NOT(CLOSED)) THEN OPEN_TRD=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;mean:&lt;/P&gt;
&lt;P&gt;if closed eq zero, then OPEN_TRD equals one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test;
set sashelp.class;

closed = age gt 13;

if (not(closed)) then a = 1;
if closed then a = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807299#M318262</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2022-04-12T07:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807302#M318264</link>
      <description>&lt;P&gt;Style comment:&lt;/P&gt;
&lt;P&gt;I inherited a bunch of code for one project that had about 150 macros that looked like this. All they did was obfuscate what the data step (yes, singular. Only used in one place) they were placed in were doing to the data. Not really reused anywhere which makes the creation of a macro a pretty problematic thing to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: your first macro %mend statement is missing a ; so may not behave as expected if that is the actual code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS only has two variable types in the basic data set: numeric and character. As such, SAS uses numeric values in the role of Boolean (logical) true/false values.&lt;/P&gt;
&lt;P&gt;This may give some ideas:&lt;/P&gt;
&lt;PRE&gt;data example;
   input x;
   if x then put 'True ' x=;
   else put 'False ' x= ;
datalines;
1
0
234
.
0.0005
-1234567
.N
1.4E12
;&lt;/PRE&gt;
&lt;P&gt;Note that every value above except 0, missing and the special missing are treated as True when used in an IF.&lt;/P&gt;
&lt;P&gt;The SAS comparisons will return 1/ 0 for true:&amp;nbsp;&amp;nbsp; Y = (x &amp;gt; 3); for example would return 0 for Y when X is less than or equal to 3 or missing (missing is always less basically so cannot be greater than 3) and 1 otherwise.&lt;/P&gt;
&lt;P&gt;This allows writing a statement like&lt;/P&gt;
&lt;PRE&gt;y = (x=1)*4.5 + (x=2)*7.3 + (x=3)* 11;&lt;/PRE&gt;
&lt;P&gt;which is equivalent to&lt;/P&gt;
&lt;PRE&gt;if x=1 then y=4.5;
else if x=2 then y=7.3;
else if x=3 then y=11;
else y=0;&lt;/PRE&gt;
&lt;P&gt;When you ask&amp;nbsp; "why" the reason becomes pretty obvious when you have a large data set (and maybe a few more X= values to use) as the IF / Then /Else code can take much longer to evaluate then the numeric computation.&lt;/P&gt;
&lt;P&gt;So if you save 0.0000001 seconds on the calculation for 1,000,000,000,000,000 records it adds up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus we get to write code that confuses new programmers.&lt;span class="lia-unicode-emoji" title=":smiling_face_with_horns:"&gt;😈&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/807302#M318264</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-12T07:41:20Z</dc:date>
    </item>
  </channel>
</rss>

