<?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: %if statement not working in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475982#M122453</link>
    <description>&lt;P&gt;There is a special character - comma . Mask it by %bquote() .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=a,b;

%put &amp;amp;x;

 

%macro new;
%do i=1 %to 2;
%let y=%scan(%bquote(&amp;amp;x),&amp;amp;i,%str(,));
%put &amp;amp;y;
%end;
%mend;

 

%new&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 06 Jul 2018 13:13:26 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-07-06T13:13:26Z</dc:date>
    <item>
      <title>%if statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475964#M122442</link>
      <description>&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;x=a,b;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;%put&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;amp;x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;STRONG&gt;&lt;SPAN&gt;%macro&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;new&lt;/I&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;%do&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;i=&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%to&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;y=&lt;/SPAN&gt;&lt;SPAN&gt;%scan&lt;/SPAN&gt;&lt;SPAN&gt;(&amp;amp;x,&amp;amp;i,',');&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;%put&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;amp;y;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;%end&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;STRONG&gt;&lt;SPAN&gt;%mend&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;%&lt;STRONG&gt;&lt;I&gt;new&lt;/I&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; operand is required. The condition was: b&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;ERROR: Argument 2 to macro function %SCAN is not a number.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;ERROR: The macro NEW will stop executing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;why I am getting this error .how can I solve this&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 12:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475964#M122442</guid>
      <dc:creator>Rohit12</dc:creator>
      <dc:date>2018-07-06T12:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: %if statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475966#M122444</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let y=%scan(%quote(&amp;amp;x),&amp;amp;i,',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %quote is needed if &amp;amp;x can have characters like a comma (and others) that would otherwise have special meaning in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, why make your life difficult by putting a comma in &amp;amp;x? If the comma isn't there, and a blank is there, then things get a little simpler&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let y=%scan(&amp;amp;x,&amp;amp;i,%str( ));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 12:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475966#M122444</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-06T12:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: %if statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475968#M122445</link>
      <description>&lt;P&gt;When &amp;amp;x is resolved, you get this call of the %scan fuinction:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%scan(a,b,&amp;amp;i,',')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since the second argument to %scan needs to be numeric, this call is invalid.&lt;/P&gt;
&lt;P&gt;It's always the same old, same old:&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;DO NOT USE THE MACRO LANGUAGE FOR DATA!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Use data steps for data, even if that data is temporarily kept in a macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=a,b;

data _null_;
y = scan("&amp;amp;x",1,',');
call symputx('y',y);
run;

%put y=&amp;amp;y;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 12:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475968#M122445</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-06T12:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: %if statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475969#M122446</link>
      <description>&lt;P&gt;It's %SCAN that is getting confused.&amp;nbsp; It sees this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let y=%scan(a,b,1,',');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It doesn't know that the first comma is just text.&amp;nbsp; It thinks the first comma marks the end of the first parameter to %SCAN, and "b" is the second parameter for %SCAN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have control over it, the simplest solution is to use a different delimiter when creating &amp;amp;x:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let x = a|b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let y=%scan(&amp;amp;x,&amp;amp;i,|);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't control that, there are more complex approaches that use macro quoting functions.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 12:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475969#M122446</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-06T12:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: %if statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475973#M122448</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It's %SCAN that is getting confused.&amp;nbsp; It sees this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let y=%scan(a,b,1,',');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It doesn't know that the first comma is just text.&amp;nbsp; It thinks the first comma marks the end of the first parameter to %SCAN, and "b" is the second parameter for %SCAN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have control over it, the simplest solution is to use a different delimiter when creating &amp;amp;x:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let x = a|b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let y=%scan(&amp;amp;x,&amp;amp;i,|);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't control that, there are more complex approaches that use macro quoting functions.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This never occurred to me, I always use a blank as a separator, but using | is actually less typing.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 12:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475973#M122448</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-06T12:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: %if statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475982#M122453</link>
      <description>&lt;P&gt;There is a special character - comma . Mask it by %bquote() .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=a,b;

%put &amp;amp;x;

 

%macro new;
%do i=1 %to 2;
%let y=%scan(%bquote(&amp;amp;x),&amp;amp;i,%str(,));
%put &amp;amp;y;
%end;
%mend;

 

%new&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 13:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement-not-working-in-macro/m-p/475982#M122453</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-06T13:13:26Z</dc:date>
    </item>
  </channel>
</rss>

