<?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 loop does not function with special text string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489450#M127801</link>
    <description>&lt;P&gt;Actually, you omitted the code that is causing the problem.&amp;nbsp; It's likely that you can switch from %SCAN to %QSCAN to solve the problem but we may need to see the code indicated by "............"&lt;/P&gt;</description>
    <pubDate>Thu, 23 Aug 2018 23:51:47 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-08-23T23:51:47Z</dc:date>
    <item>
      <title>macro loop does not function with special text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489435#M127788</link>
      <description>&lt;P&gt;I have the following Macro code:&lt;/P&gt;&lt;P&gt;%macro LTV_DSCR(file1,file2,var,bins,lm1,lm2,rounding);&lt;BR /&gt;%local i j part1 part2;&lt;BR /&gt;%let i=1;&lt;BR /&gt;%do %while(%scan(%str(&amp;amp;file1), &amp;amp;i) ne);&lt;BR /&gt;%let part1=%scan(%str(%&amp;amp;file1), &amp;amp;i);&lt;BR /&gt;%let j=1;&lt;BR /&gt;%do %while(%scan(%str(%&amp;amp;file2), &amp;amp;j) ne);&lt;BR /&gt;%let part2=%scan(%str(%&amp;amp;file2), &amp;amp;j);&lt;/P&gt;&lt;P&gt;..........&lt;/P&gt;&lt;P&gt;%let j=%eval(&amp;amp;j+1);&lt;BR /&gt;%end;&lt;BR /&gt;%let i=%eval(&amp;amp;i+1);&lt;BR /&gt;%end;&lt;BR /&gt;%mend LTV_DSCR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LTVDSCR(RT OR OF IN MF LO, W SE SW MW NE, LTV, 10, 2.5, 4, 0.1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code gives error message:&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;%scan(&amp;amp;file1, &amp;amp;i) ne&lt;BR /&gt;ERROR: The condition in the %DO %WHILE loop, %scan(&amp;#1;&amp;amp;file1&amp;#2;, &amp;amp;i) ne, yielded an invalid or missing value, . The macro will stop&lt;BR /&gt;executing.&lt;BR /&gt;ERROR: The macro LTV_DSCR will stop executing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This only happens when it reaches word like "OR" "NA".&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I modify my code?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 22:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489435#M127788</guid>
      <dc:creator>funnybunny78</dc:creator>
      <dc:date>2018-08-23T22:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop does not function with special text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489436#M127789</link>
      <description>&lt;P&gt;Yes, those are reserved words in SAS Macro language, ie OR is logical operator OR, not Oregon as you're likely using it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if these help you out:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 22:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489436#M127789</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-23T22:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop does not function with special text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489444#M127796</link>
      <description>&lt;P&gt;Hi, I tried most macro function suggested in the article, and none works.&amp;nbsp; Can someone be more specific about how to resolve this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 22:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489444#M127796</guid>
      <dc:creator>funnybunny78</dc:creator>
      <dc:date>2018-08-23T22:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop does not function with special text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489450#M127801</link>
      <description>&lt;P&gt;Actually, you omitted the code that is causing the problem.&amp;nbsp; It's likely that you can switch from %SCAN to %QSCAN to solve the problem but we may need to see the code indicated by "............"&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 23:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489450#M127801</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-23T23:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop does not function with special text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489451#M127802</link>
      <description>&lt;P&gt;The link given specifically shows what to do with OR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it doesn't work, show us what you tried.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 23:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489451#M127802</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-23T23:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop does not function with special text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489461#M127808</link>
      <description>&lt;P&gt;Make sure you catch all the problematic words, in this case likely:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR, OF, NE at minimum.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It helps if you turn on MPRINT/SYMBOLGEN to see issues in the log and it identifies the problematic portion in more detail.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 00:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489461#M127808</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-24T00:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop does not function with special text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489519#M127846</link>
      <description>&lt;P&gt;Replace that macro code with data step code, and it will be a lot easier.&lt;/P&gt;
&lt;P&gt;First, wrap the ....... code into its own macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_single(part1,part2,var,bins,lm1,lm2,rounding);
........
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then restructure your outer macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro LTV_DSCR(file1,file2,var,bins,lm1,lm2,rounding);
data _null_;
do i = 1 to countw("&amp;amp;file1", ' ');
  part1 = scan("&amp;amp;file1",i,' ');
  do j = 1 to countw("&amp;amp;file2",' ');
    part2 = scan("&amp;amp;file2",j,' ');
    call execute('%nrstr(%do_single(' !! trim(part1) !! ',' !! trim(part2) !! ",&amp;amp;var,&amp;amp;bins,&amp;amp;lm1,&amp;amp;lm2,&amp;amp;rounding))");
  end;
end;
run;
%mend LTV_DSCR;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the data step, there is no reason to consider anything in a string a "special word" that needs to be masked.&lt;/P&gt;
&lt;P&gt;See this simple example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_single(part1,part2,var,bins,lm1,lm2,rounding);
%put &amp;amp;part1;
%put &amp;amp;part2;
%put &amp;amp;rounding;
%mend;

%macro LTV_DSCR(file1,file2,var,bins,lm1,lm2,rounding);
data _null_;
do i = 1 to countw("&amp;amp;file1", ' ');
  part1 = scan("&amp;amp;file1",i,' ');
  do j = 1 to countw("&amp;amp;file2",' ');
    part2 = scan("&amp;amp;file2",j,' ');
    call execute('%nrstr(%do_single(' !! trim(part1) !! ',' !! trim(part2) !! ",&amp;amp;var,&amp;amp;bins,&amp;amp;lm1,&amp;amp;lm2,&amp;amp;rounding))");
  end;
end;
run;
%mend LTV_DSCR;

%LTV_DSCR(RT OR OF IN MF LO, W SE SW MW NE, LTV, 10, 2.5, 4, 0.1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Abbreviated log from that:&lt;/P&gt;
&lt;PRE&gt;45         %LTV_DSCR(RT OR OF IN MF LO, W SE SW MW NE, LTV, 10, 2.5, 4, 0.1);

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: CALL EXECUTE generated line.
1         + %do_single(RT,W,LTV,10,2.5,4,0.1)
RT
W
0.1
2         + %do_single(RT,SE,LTV,10,2.5,4,0.1)
RT
SE
0.1
&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Aug 2018 08:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-does-not-function-with-special-text-string/m-p/489519#M127846</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-24T08:16:58Z</dc:date>
    </item>
  </channel>
</rss>

