<?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 Error : Issue in do loop comparison with character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-Issue-in-do-loop-comparison-with-character-variable/m-p/719818#M222922</link>
    <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;Hi,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;I have a requirement to&amp;nbsp; truncate all the tables in DB2 environment from SAS. I have written a below query in a loop and I'm facing few issues.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;connect to DB2(datasrc=XXXXX authdomain="XXXXX");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;select * into :tablename from connection to db2 (&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;select tabname &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;from &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;SYSCAT.TABLES &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;where TABSCHEMA = %str(%')%upcase(TEST)%str(%') and &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;TYPE = %str(%')%upcase(T)%str(%')&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;disconnect from DB2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%let tablename1 = &amp;amp;tablename.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%macro truncate_table;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%do i = 1 %to &amp;amp;tablename1.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;connect to DB2(datasrc=XXXXX authdomain="XXXXX");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;exec ( truncate table TEST.&amp;amp;tablename1. immediate );&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;disconnect from DB2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;quit;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%mend;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%truncate_table;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;Below is my error message&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;&amp;amp;tablename1. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;ERROR: The macro TRUNCATE_TABLE will stop executing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" color="#000000"&gt;Please let me know where I went wrong. Thanks&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Feb 2021 07:02:02 GMT</pubDate>
    <dc:creator>helannivas88</dc:creator>
    <dc:date>2021-02-17T07:02:02Z</dc:date>
    <item>
      <title>Error : Issue in do loop comparison with character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-Issue-in-do-loop-comparison-with-character-variable/m-p/719818#M222922</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;Hi,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;I have a requirement to&amp;nbsp; truncate all the tables in DB2 environment from SAS. I have written a below query in a loop and I'm facing few issues.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;connect to DB2(datasrc=XXXXX authdomain="XXXXX");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;select * into :tablename from connection to db2 (&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;select tabname &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;from &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;SYSCAT.TABLES &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;where TABSCHEMA = %str(%')%upcase(TEST)%str(%') and &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;TYPE = %str(%')%upcase(T)%str(%')&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;disconnect from DB2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%let tablename1 = &amp;amp;tablename.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%macro truncate_table;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%do i = 1 %to &amp;amp;tablename1.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;connect to DB2(datasrc=XXXXX authdomain="XXXXX");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;exec ( truncate table TEST.&amp;amp;tablename1. immediate );&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;disconnect from DB2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;quit;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%mend;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;%truncate_table;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;Below is my error message&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;&amp;amp;tablename1. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" color="#FF0000"&gt;ERROR: The macro TRUNCATE_TABLE will stop executing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" color="#000000"&gt;Please let me know where I went wrong. Thanks&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 07:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Issue-in-do-loop-comparison-with-character-variable/m-p/719818#M222922</guid>
      <dc:creator>helannivas88</dc:creator>
      <dc:date>2021-02-17T07:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Error : Issue in do loop comparison with character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-Issue-in-do-loop-comparison-with-character-variable/m-p/719823#M222923</link>
      <description>&lt;P&gt;Few remarks to your code:&lt;/P&gt;
&lt;P&gt;1) Try replace&amp;nbsp;&lt;STRONG&gt;%str(%')%upcase(TEST)%str(%')&amp;nbsp;&lt;/STRONG&gt; by&amp;nbsp;&lt;STRONG&gt;%quote(%upacse(TEST))&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2) I suppose that&amp;nbsp;&lt;STRONG&gt;tabname&lt;/STRONG&gt; is a string entered into the macro variable&amp;nbsp;&lt;STRONG&gt;tablename&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; and then assigned to&amp;nbsp;&lt;STRONG&gt;tabelname1&amp;nbsp;&lt;/STRONG&gt; - then what does next line mean?&lt;/P&gt;
&lt;PRE&gt;%do i = 1 %to &amp;amp;tablename1.;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;I guess that&amp;nbsp;&lt;STRONG&gt;tablename&lt;/STRONG&gt; contains a list of tables' names and you want to execute&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;%truncate_table&lt;/STRONG&gt; with each of the names. If so then you need to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * into :tablename separated by " "
    from connection to db2( ... etc ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; and&amp;nbsp;&amp;nbsp;count the number&amp;nbsp;&amp;nbsp;of names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 %to %sysfunc(countw(&amp;amp;tablename));
     %let tablename1 = %scan(&amp;amp;tablename,&amp;amp;i);
     ... etc. ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I hope the other code relating to DB2 is OK.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 08:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Issue-in-do-loop-comparison-with-character-variable/m-p/719823#M222923</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-17T08:04:39Z</dc:date>
    </item>
  </channel>
</rss>

