<?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: %local question in my code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515665#M139166</link>
    <description>&lt;P&gt;Run the program again without the %LOCAL statement. Show us the SASLOG. Click on the {i} icon and paste the SASLOG into that window.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Nov 2018 21:12:05 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-11-23T21:12:05Z</dc:date>
    <item>
      <title>%local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515652#M139165</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic mprint symbolgen;
data sample_name;
   input id name $;
   cards ;
   1 DAVID
   2 JOHN
   3 JOSH
   ;
run;


%macro mcr_test(dst_term);
%local nm;
proc sql;
select DISTINCT name
into :nm
from sample_name
where %upcase(name)=%upcase("&amp;amp;dst_term");
quit;
%put &amp;amp;nm;
data _null_;   
%if &amp;amp;dst_term=&amp;amp;nm %then %do;
 %put "step1";
%end;
%else %do;
 %put "step2";
%end;
run;
%mend;
%mcr_test(DAVID);
%mcr_test(ANDY);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I wrote this macro to print "step 1" when passing parameter is in sample_name dataset, if not print "step 2". if we can write it efficiently I take suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above code running fine when I added &lt;STRONG&gt;&lt;FONT color="#800080"&gt;%local nm;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#000000"&gt; to macro.&amp;nbsp; without %local I am getting below error.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; operand is required. The condition was: &amp;amp;dst_term=&amp;amp;nm&lt;BR /&gt;ERROR: The macro MCR_TEST will stop executing.&lt;BR /&gt;MLOGIC(MCR_TEST):&amp;nbsp; Ending execution..&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;Anybody explain the difference and mechanism of SAS process.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;Thank you.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 20:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515652#M139165</guid>
      <dc:creator>nbonda</dc:creator>
      <dc:date>2018-11-23T20:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515665#M139166</link>
      <description>&lt;P&gt;Run the program again without the %LOCAL statement. Show us the SASLOG. Click on the {i} icon and paste the SASLOG into that window.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 21:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515665#M139166</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-23T21:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515693#M139181</link>
      <description>&lt;PRE&gt;2    options mlogic mprint symbolgen;
3    data sample_name;
4       input id name $;
5       cards ;

NOTE: The data set WORK.SAMPLE_NAME has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.04 seconds


9       ;
10   run;
11
12
13   %macro mcr_test(dst_term);
14   /*%local nm;*/
15   proc sql;
16   select DISTINCT name
17   into :nm
18   from sample_name
19   where %upcase(name)=%upcase("&amp;amp;dst_term");
20   quit;
21   %put &amp;amp;nm;
22   data _null_;
23   %if &amp;amp;dst_term=&amp;amp;nm %then %do;
24    %put "step1";
25   %end;
26   %else %do;
27    %put "step2";
28   %end;
29   run;
30   %mend;
31   %mcr_test(DAVID);
MLOGIC(MCR_TEST):  Beginning execution.
MLOGIC(MCR_TEST):  Parameter DST_TERM has value DAVID
MPRINT(MCR_TEST):   proc sql;
SYMBOLGEN:  Macro variable DST_TERM resolves to DAVID
MPRINT(MCR_TEST):   select DISTINCT name into :nm from sample_name where NAME="DAVID";
NOTE: Writing HTML Body file: sashtml.htm
MPRINT(MCR_TEST):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.71 seconds
      cpu time            0.46 seconds


MLOGIC(MCR_TEST):  %PUT &amp;amp;nm
SYMBOLGEN:  Macro variable NM resolves to DAVID
DAVID
MPRINT(MCR_TEST):   data _null_;
SYMBOLGEN:  Macro variable DST_TERM resolves to DAVID
SYMBOLGEN:  Macro variable NM resolves to DAVID
MLOGIC(MCR_TEST):  %IF condition &amp;amp;dst_term=&amp;amp;nm is TRUE
MLOGIC(MCR_TEST):  %PUT "step1"
"step1"
MPRINT(MCR_TEST):   run;

NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds


MLOGIC(MCR_TEST):  Ending execution.
32   %mcr_test(ANDY);
MLOGIC(MCR_TEST):  Beginning execution.
MLOGIC(MCR_TEST):  Parameter DST_TERM has value ANDY
MPRINT(MCR_TEST):   proc sql;
SYMBOLGEN:  Macro variable DST_TERM resolves to ANDY
MPRINT(MCR_TEST):   select DISTINCT name into :nm from sample_name where NAME="ANDY";
NOTE: No rows were selected.
MPRINT(MCR_TEST):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


MLOGIC(MCR_TEST):  %PUT &amp;amp;nm
WARNING: Apparent symbolic reference NM not resolved.
&amp;amp;nm
MPRINT(MCR_TEST):   data _null_;
SYMBOLGEN:  Macro variable DST_TERM resolves to ANDY
WARNING: Apparent symbolic reference NM not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: &amp;amp;dst_term=&amp;amp;nm
ERROR: The macro MCR_TEST will stop executing.
MLOGIC(MCR_TEST):  Ending execution.
&lt;/PRE&gt;
&lt;P&gt;hi Paige Miller,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;log inserted.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Nov 2018 02:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515693#M139181</guid>
      <dc:creator>nbonda</dc:creator>
      <dc:date>2018-11-24T02:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515710#M139195</link>
      <description>&lt;P&gt;When you use the INTO clause to try to create a macro variable, but the query does not return any observations the macro variable is NOT created.&amp;nbsp; But when you have a %LOCAL statement to define a macro variable it is defined immediately.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not need to run a macro to see that behavior.&lt;/P&gt;
&lt;PRE&gt;85   proc sql noprint;
86    select name into :name
87    from sashelp.class
88    where name = 'sandy'
89    ;
NOTE: No rows were selected.
90   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.14 seconds
      cpu time            0.01 seconds


WARNING: Apparent symbolic reference NAME not resolved.
91   %put name=&amp;amp;name;
name=&amp;amp;name&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Nov 2018 08:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515710#M139195</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-24T08:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515714#M139196</link>
      <description>&lt;P&gt;You messed up the macro language and data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic mprint symbolgen;
data sample_name;
   input id name $;
   cards ;
   1 DAVID
   2 JOHN
   3 JOSH
   ;
run;


%macro mcr_test(dst_term);
%local nm;
proc sql;
select DISTINCT name
into :nm
from sample_name
where upcase(name)="%upcase(&amp;amp;dst_term)";
quit;
%put &amp;amp;nm;
data _null_;   
%if &amp;amp;dst_term=&amp;amp;nm %then %do;
 %put "step1";
%end;
%else %do;
 %put "step2";
%end;
run;
%mend;
%mcr_test(DAVID)
%mcr_test(ANDY)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Nov 2018 10:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515714#M139196</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-24T10:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515721#M139198</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38386"&gt;@nbonda&lt;/a&gt;&amp;nbsp;wrote:&amp;nbsp;
&lt;P&gt;(...)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;FONT color="#000000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; operand is required. The condition was: &amp;amp;dst_term=&amp;amp;nm&lt;BR /&gt;ERROR: The macro MCR_TEST will stop executing.&lt;BR /&gt;MLOGIC(MCR_TEST):&amp;nbsp; Ending execution..&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;Anybody explain the difference and mechanism of SAS process.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;Thank you.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Let's walk through the two executions of your macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Macro MCR_TEST is called with parameter value DAVID:&lt;/U&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The %LOCAL statement creates a macro variable NM in the macro's local symbol table.&lt;/LI&gt;
&lt;LI&gt;Macro language elements (recognized by leading % or &amp;amp; signs) in the PROC SQL step are resolved: &lt;FONT face="courier new,courier"&gt;%upcase(name)&lt;/FONT&gt; resolves to &lt;FONT face="courier new,courier"&gt;NAME&lt;/FONT&gt; (and &lt;EM&gt;not&lt;/EM&gt; to anything involving the values in dataset SAMPLE_NAME -- see how &lt;STRONG&gt;Ksharp&lt;/STRONG&gt; corrected this) and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%upcase("&amp;amp;dst_term")&lt;/FONT&gt; resolves to &lt;FONT face="courier new,courier"&gt;"DAVID"&lt;/FONT&gt;&amp;nbsp;(including the double quotes).&lt;/LI&gt;
&lt;LI&gt;Now that the macro processor has resolved these macro language elements, the PROC SQL step is compiled and executed, which populates macro variable NM with the value &lt;FONT face="courier new,courier"&gt;DAVID&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;The %PUT statement is executed: The value of NM (i.e. &lt;FONT face="courier new,courier"&gt;DAVID&lt;/FONT&gt;) is written to the log.&lt;/LI&gt;
&lt;LI&gt;Similarly to step 2, macro language in the DATA step is&amp;nbsp;resolved: Both macro variable references in the %IF condition resolve to &lt;FONT face="courier new,courier"&gt;DAVID&lt;/FONT&gt;, i.e., the condition is met. Hence, only the first %PUT statement is executed: &lt;FONT face="courier new,courier"&gt;"step1"&lt;/FONT&gt; (including unnecessary double quotes) is written to the log.&lt;/LI&gt;
&lt;LI&gt;The DATA step is compiled and executed. After the macro processor has finished its work (see step 5) this is an &lt;EM&gt;empty&lt;/EM&gt; DATA step (&lt;FONT face="courier new,courier"&gt;data _null_; run;&lt;/FONT&gt;), so this is useless.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Without the %LOCAL statement the PROC SQL step creates the local macro variable NM (assuming that no global macro variable NM exists). No change in steps 2 - 6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Macro MCR_TEST is called with parameter value ANDY:&lt;/U&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;as above.&lt;/LI&gt;
&lt;LI&gt;as above, except that this time&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%upcase("&amp;amp;dst_term")&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;resolves to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;"ANDY"&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;The PROC SQL step is compiled and executed, but this time macro variable NM remains empty because no row of dataset SAMPLE_NAME meets the condition &lt;FONT face="courier new,courier"&gt;NAME="ANDY"&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;The value of NM (i.e. a null string) is written to the log.&lt;/LI&gt;
&lt;LI&gt;Macro language in the DATA step is&amp;nbsp;resolved: The condition that the string &lt;FONT face="courier new,courier"&gt;ANDY&lt;/FONT&gt; is equal to the null string is false. Hence, only the second %PUT statement is executed: &lt;FONT face="courier new,courier"&gt;"step2"&lt;/FONT&gt; (including unnecessary double quotes) is written to the log.&lt;/LI&gt;
&lt;LI&gt;as above.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Without the %LOCAL statement macro variable NM does not exist because the PROC SQL step (selecting no rows) doesn't create it (as &lt;STRONG&gt;Tom&lt;/STRONG&gt; has pointed out already). As a consequence, the macro variable references &lt;FONT face="courier new,courier"&gt;&amp;amp;nm&lt;/FONT&gt; in the %PUT statement and in the %IF condition cannot be resolved (causing two identical warnings in the log: &lt;FONT face="courier new,courier" color="#008000"&gt;WARNING: Apparent symbolic reference NM not resolved.&lt;/FONT&gt;). In step 4 the %PUT statement writes the unresolved text &lt;FONT face="courier new,courier"&gt;&amp;amp;nm&lt;/FONT&gt; to the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even worse, the %IF condition resolves to &lt;FONT face="courier new,courier"&gt;ANDY=&amp;amp;nm&lt;/FONT&gt;, which the macro processor tries to interpret as a compound logical expression consisting of&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the expression&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ANDY=&lt;/FONT&gt; (saying "the string &lt;FONT face="courier new,courier"&gt;ANDY&lt;/FONT&gt; equals the null string")&lt;/LI&gt;
&lt;LI&gt;the expression &lt;FONT face="courier new,courier"&gt;nm&lt;/FONT&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;joined by the Boolean operator AND (written as &lt;FONT face="courier new,courier" size="3"&gt;&amp;amp;&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While &lt;FONT face="courier new,courier"&gt;ANDY=&lt;/FONT&gt; is a valid logical expression and evaluates to (the Boolean value) FALSE, the string &lt;FONT face="courier new,courier"&gt;nm&lt;/FONT&gt; is not valid in this context. An integer&amp;nbsp;number (or another logical expression for that matter) in place of &lt;FONT face="courier new,courier"&gt;nm&lt;/FONT&gt; would be valid (e.g. &lt;FONT face="courier new,courier"&gt;ANDY=&amp;amp;5&lt;/FONT&gt;) because non-zero&amp;nbsp;integers are evaluated to TRUE and 0 to FALSE. So, it is the string&amp;nbsp;&lt;FONT face="courier new,courier"&gt;nm&lt;/FONT&gt;&amp;nbsp;which the error message refers to as a "&lt;FONT face="courier new,courier" color="#FF0000"&gt;character operand ... where a numeric operand is required.&lt;/FONT&gt;" Due to this error, the macro stops executing in the middle of processing the macro language elements in the DATA step code. Finally, the DATA _NULL_ statement, but not the RUN statement (which had not been reached yet) is executed, leaving the SAS session in the state "DATA STEP running".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38386"&gt;@nbonda&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;I wrote this macro to print "step 1" when passing parameter is in sample_name dataset, if not print "step 2". if we can write it efficiently I take suggestions.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The second part of the macro code (between &lt;FONT face="courier new,courier"&gt;%put nm;&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;%mend;&lt;/FONT&gt;) could be simplified to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;dst_term=&amp;amp;nm %then %put step1;
%else %put step2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No DATA step is required (it would be empty, see above), no %DO-%END blocks (there's only &lt;EM&gt;one&lt;/EM&gt;&amp;nbsp;statement in each block) and no quotation marks around the strings to be written to the log (the macro language would treat them as additional text). However, the %IF condition is still case-sensitive. So, depending on what you want to achieve, you may want to apply the %UPCASE function in the %IF condition or make sure that macro variables DST_TERM and NM contain only upper-case strings at this point (e.g. write&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let dst_term=%upcase(&amp;amp;dst_term);&lt;/FONT&gt; at the beginning of the macro and use the UPCASE function in the SELECT statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correction of the WHERE clause has been mentioned already. The DISTINCT keyword is not mandatory for the INTO clause (which in any case writes only the &lt;EM&gt;first&lt;/EM&gt; selected value into the macro variable), but has the (intended?) side effect that multiple selected values, if any, are &lt;EM&gt;sorted&lt;/EM&gt; so that &lt;FONT face="courier new,courier"&gt;DAVID&lt;/FONT&gt; would always precede &lt;FONT face="courier new,courier"&gt;David&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;david&lt;/FONT&gt;&amp;nbsp;(assuming the ASCII collating sequence) and hence the upper-case value would be written to macro variable NM, regardless of the order of observations in dataset SAMPLE_NAME.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Nov 2018 14:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515721#M139198</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-24T14:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515722#M139199</link>
      <description>Thank you. I was under impression that a function should be macro function within macro. Now I understand where to use macro function.</description>
      <pubDate>Sat, 24 Nov 2018 14:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515722#M139199</guid>
      <dc:creator>nbonda</dc:creator>
      <dc:date>2018-11-24T14:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515723#M139200</link>
      <description>thank you</description>
      <pubDate>Sat, 24 Nov 2018 14:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515723#M139200</guid>
      <dc:creator>nbonda</dc:creator>
      <dc:date>2018-11-24T14:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: %local question in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515737#M139214</link>
      <description>&lt;P&gt;You can also use the automatic macro variable SQLOBS to check if your query&amp;nbsp;returned&amp;nbsp;any observations.&lt;/P&gt;
&lt;P&gt;Also be careful to distinguish between where you want macro functions (to test text and generate code) and actual SAS functions and SAS statements.&amp;nbsp; For example you were using macro function %UPCASE() to turn the string name into the string NAME instead of the SAS function UPCASE() to operate on the value of the variable named NAME.&amp;nbsp; You enclosed a block of pure macro code inside of a data _null_ step for no reason since the macro code did not generate any statements that would run in that data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mcr_test(dst_term);
%local nm n;
proc sql noprint;
  select name
    into :nm trimmed
  from sample_name
  where upcase(name)=%upcase("&amp;amp;dst_term")
  ;
%let n=&amp;amp;sqlobs;
quit;
data _null_;
  %if &amp;amp;n %then %do;
     put "Found name=&amp;amp;nm";
  %end;
  %else %do;
    put "Did not find name= &amp;amp;dst_term";
  %end;
run;
%mend;
%mcr_test(David);
%mcr_test(ANDY);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Results:&lt;/P&gt;
&lt;PRE&gt;160  %mcr_test(David);
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds



Found name=DAVID
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.00 seconds


161  %mcr_test(ANDY);
NOTE: No rows were selected.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds



Did not find name= ANDY
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Nov 2018 19:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-question-in-my-code/m-p/515737#M139214</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-24T19:37:27Z</dc:date>
    </item>
  </channel>
</rss>

