<?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 %then character operand error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361727#M274760</link>
    <description>&lt;P&gt;i had a compress statement &amp;nbsp;noted out for some reason, which is where the '-' snuck in. I didn't even realize when I copied it over. Thanks for spotting that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, my new problem, is that my loop only creates the report for the first&amp;nbsp;%if %then:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%if &amp;amp;error=ContactHr %then %do;&lt;/P&gt;&lt;P&gt;proc report 1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%else %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In reality, I have several %if statements that I need fulfilled. For instance:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%if &amp;amp;error=ContactHr %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%else&amp;nbsp;%if &amp;amp;error=table %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc&amp;nbsp;report2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;going on like that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, I cannot get it to move past the first itineration of %if %then. It satitifies then doesn't move to the next %if %then, which leads me to think it closing the loop early.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;again full code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%let k=1;&lt;BR /&gt;%let error = %scan(&amp;amp;tsdselement,&amp;amp;k,'*'); /*picks the first error in list we have */&lt;BR /&gt;%do %while ("&amp;amp;error" ^= ""); /*loop until the list is done*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;%if &amp;amp;error=ContactHr %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%else&amp;nbsp;%if &amp;amp;error=table %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Error list loop*/&lt;BR /&gt;%let k = %eval(&amp;amp;k + 1); /* redfine the value of k so that the loop continues the 2nd ,3rd, etc. word in the list*/&lt;BR /&gt;%let error = %scan(&amp;amp;tsdselement,&amp;amp;k,'*');&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2017 18:15:47 GMT</pubDate>
    <dc:creator>sasiscool</dc:creator>
    <dc:date>2017-05-25T18:15:47Z</dc:date>
    <item>
      <title>%IF %then character operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361714#M274757</link>
      <description>&lt;P&gt;I have a&amp;nbsp;macro loop that spits out reports. However, I want to include an %if %then clause to conditionally change my proc report slightly under certain conditions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro TSDS_ERROR (tsdselement);&lt;/P&gt;&lt;P&gt;%let k=1;&lt;BR /&gt;%let error = %scan(&amp;amp;tsdselement,&amp;amp;k,'*'); /*picks the first error in list we have */&lt;BR /&gt;%do %while ("&amp;amp;error" ^= ""); /*loop until the list is done*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if &amp;amp;error=ContactHr %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc report 1 code.......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report 2&amp;nbsp;code.......&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let k = %eval(&amp;amp;k + 1); /* redfine the value of k so that the loop continues the 2nd ,3rd, etc. word in the list*/&lt;BR /&gt;%let error = %scan(&amp;amp;tsdselement,&amp;amp;k,'*');&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%TSDS_ERROR (ContactHr*apple*Loc-orange*....);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I get the common Error:&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 required. The condition was:&lt;BR /&gt;&amp;amp;error=ContactHr&lt;BR /&gt;ERROR: The macro TSDS_ERROR will stop executing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some articles on the topic, but stil can't seem to get passed this error, so that it will accept characters. Any Advise?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again SAS forums!&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 17:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361714#M274757</guid>
      <dc:creator>sasiscool</dc:creator>
      <dc:date>2017-05-25T17:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: %IF %then character operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361719#M274758</link>
      <description>&lt;P&gt;The problem arises because some strings in your list can contain a dash.&amp;nbsp; Consider how SAS interprets this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if Loc-orange = ContactHr %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro language interprets the dash as a request to perform subtraction, giving you your error message.&amp;nbsp; The simplest fix might be this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let error = "%scan(&amp;amp;tsdselement,&amp;amp;k,*)";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you don't need quotes around the * in macro language (unless you want quotes to be used as a delimiter by %SCAN).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the comparison would become:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;error ne "ContactHr" %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Double quotes suppress the interpretation of a dash as subtraction.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you might need to check the proper construction of your %DO %WHILE condition, but a little experimentation should let you work that out.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 17:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361719#M274758</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-25T17:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: %IF %then character operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361724#M274759</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i do want the quotes to be used as a delimiter for the %scan. The delimiter in this list is '*'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;why must the logic be inversered rather than direct? &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%if &amp;amp;error ne "ContactHr" %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sure, this can get my where I need to go by reverse, but I am still uncelar as to&amp;nbsp;why a plain &amp;nbsp;&amp;amp;error=ContactHr will not work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thanks again!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 18:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361724#M274759</guid>
      <dc:creator>sasiscool</dc:creator>
      <dc:date>2017-05-25T18:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: %IF %then character operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361727#M274760</link>
      <description>&lt;P&gt;i had a compress statement &amp;nbsp;noted out for some reason, which is where the '-' snuck in. I didn't even realize when I copied it over. Thanks for spotting that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, my new problem, is that my loop only creates the report for the first&amp;nbsp;%if %then:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%if &amp;amp;error=ContactHr %then %do;&lt;/P&gt;&lt;P&gt;proc report 1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%else %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In reality, I have several %if statements that I need fulfilled. For instance:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%if &amp;amp;error=ContactHr %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%else&amp;nbsp;%if &amp;amp;error=table %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc&amp;nbsp;report2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;going on like that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, I cannot get it to move past the first itineration of %if %then. It satitifies then doesn't move to the next %if %then, which leads me to think it closing the loop early.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;again full code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%let k=1;&lt;BR /&gt;%let error = %scan(&amp;amp;tsdselement,&amp;amp;k,'*'); /*picks the first error in list we have */&lt;BR /&gt;%do %while ("&amp;amp;error" ^= ""); /*loop until the list is done*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;%if &amp;amp;error=ContactHr %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%else&amp;nbsp;%if &amp;amp;error=table %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc report 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Error list loop*/&lt;BR /&gt;%let k = %eval(&amp;amp;k + 1); /* redfine the value of k so that the loop continues the 2nd ,3rd, etc. word in the list*/&lt;BR /&gt;%let error = %scan(&amp;amp;tsdselement,&amp;amp;k,'*');&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 18:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361727#M274760</guid>
      <dc:creator>sasiscool</dc:creator>
      <dc:date>2017-05-25T18:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: %IF %then character operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361729#M274761</link>
      <description>&lt;P&gt;The reason concerns how an %IF condition interprets a dash.&amp;nbsp; Remember, %EVAL is applied to all %IF conditions.&amp;nbsp; Thus if a dash is present, it triggers the attempt to subtract.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider a simple case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let club = 4-H;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;club = 4-H %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming these statements are contained within a macro definition (so %IF is legal), the first statement always works.&amp;nbsp; And the second statement always generates an error.&amp;nbsp; The dash triggers %EVAL to perform subtraction.&amp;nbsp; However, this comparison would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if "&amp;amp;club" = "4-H" %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By adding the double quotes, %EVAL now figures out it should perform a character comparison and not attempt to subtract.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This post was in response to&amp;nbsp; your post #3.&amp;nbsp; Regarding your post #4, try inserting some diagnostics.&amp;nbsp; After assigning a value to &amp;amp;error, display the value with a %PUT statement.&amp;nbsp; Better yet, turn on debugging options such as MLOGIC and SYMBOLGEN.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 18:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-character-operand-error/m-p/361729#M274761</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-25T18:24:04Z</dc:date>
    </item>
  </channel>
</rss>

