<?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: Macro %IF fails when variable has minus sign in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376335#M90325</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16582"&gt;@milts&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;This is a very silly beginner question but would like to seek some advise. I'm getting this error when the value of the macro variable layer has a dash. Seems like it's still trying to evaluate it even I have placed %str.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the error I get and the code sample below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is&lt;BR /&gt;required. The condition was: &amp;amp;layer = stg or &amp;amp;layer = stg-m&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;
%let layer=stg-m;

%macro test;
	%if %str(&amp;amp;layer) = %str(stg) or %str(&amp;amp;layer) = %str(stg-m) %then %do;
		%put CORRECT;
	%end;
%mend;

%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to use %quote around &amp;amp;layer, and you don't need to include stg in the %str() function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %quote(&amp;amp;layer) = stg or %quote(&amp;amp;layer) = %str(stg-m) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 16 Jul 2017 13:07:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-07-16T13:07:11Z</dc:date>
    <item>
      <title>Macro %IF fails when variable has minus sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376333#M90323</link>
      <description>&lt;P&gt;This is a very silly beginner question but would like to seek some advise. I'm getting this error when the value of the macro variable layer has a dash. Seems like it's still trying to evaluate it even I have placed %str.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error I get and the code sample below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is&lt;BR /&gt;required. The condition was: &amp;amp;layer = stg or &amp;amp;layer = stg-m&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;
%let layer=stg-m;

%macro test;
	%if %str(&amp;amp;layer) = %str(stg) or %str(&amp;amp;layer) = %str(stg-m) %then %do;
		%put CORRECT;
	%end;
%mend;

%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Jul 2017 11:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376333#M90323</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2017-07-16T11:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro %IF fails when variable has minus sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376334#M90324</link>
      <description>I guess that som quoting macro will work, but perhaps a simpler approach would to include single quotes in you macro variable values.</description>
      <pubDate>Sun, 16 Jul 2017 12:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376334#M90324</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-07-16T12:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro %IF fails when variable has minus sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376335#M90325</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16582"&gt;@milts&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;This is a very silly beginner question but would like to seek some advise. I'm getting this error when the value of the macro variable layer has a dash. Seems like it's still trying to evaluate it even I have placed %str.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the error I get and the code sample below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is&lt;BR /&gt;required. The condition was: &amp;amp;layer = stg or &amp;amp;layer = stg-m&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;
%let layer=stg-m;

%macro test;
	%if %str(&amp;amp;layer) = %str(stg) or %str(&amp;amp;layer) = %str(stg-m) %then %do;
		%put CORRECT;
	%end;
%mend;

%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to use %quote around &amp;amp;layer, and you don't need to include stg in the %str() function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %quote(&amp;amp;layer) = stg or %quote(&amp;amp;layer) = %str(stg-m) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jul 2017 13:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376335#M90325</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-07-16T13:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro %IF fails when variable has minus sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376336#M90326</link>
      <description>&lt;P&gt;A simple solution is to add double quotes around everything:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if "&amp;amp;layer" = "stg" or "&amp;amp;layer" = "stg-m" %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The double quotes suppress macro language's urge to treat the dash as an instruction to subtract.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this to work, you have to be careful to construct &amp;amp;LAYER with no leading or trailing blanks.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jul 2017 13:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376336#M90326</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-16T13:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro %IF fails when variable has minus sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376534#M90390</link>
      <description>&lt;P&gt;Yeah. minus is a special character for macro facility, you need mask it.&lt;/P&gt;
&lt;P&gt;Since it is in a macro variable ,use %bquote() better. %str() is for string .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;
%let layer=stg-m;

%macro test;
	%if %bquote(&amp;amp;layer) = %str(stg) or %bquote(&amp;amp;layer) = %str(stg-m) %then %do;
		%put CORRECT;
	%end;
%mend;

%test&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2017 13:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376534#M90390</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-17T13:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro %IF fails when variable has minus sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376535#M90391</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;
%let layer=stg-m;

%macro test/minoperator mindelimiter=' ';
	%if %bquote(&amp;amp;layer) in %str(stg) %str(stg-m) %then %do;
		%put CORRECT;
	%end;
%mend;

%test&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2017 13:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-fails-when-variable-has-minus-sign/m-p/376535#M90391</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-17T13:26:46Z</dc:date>
    </item>
  </channel>
</rss>

