<?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: condition on a macro-variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161932#M42119</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all very much for helping me. It works when I write %BQUOTE! Thanks again&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Dec 2013 14:52:41 GMT</pubDate>
    <dc:creator>sofisaas</dc:creator>
    <dc:date>2013-12-03T14:52:41Z</dc:date>
    <item>
      <title>condition on a macro-variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161927#M42114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an issue with a macro-variable. I have set up a macro in which I collect values of two macro variable (call symput). But when I try to write a condition on the value of one of these macro variable, I have an error message which tells me :&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found &lt;SPAN style="color: #0000ff;"&gt;IN&lt;/SPAN&gt; the %EVAL &lt;SPAN style="color: #0000ff;"&gt;FUNCTION&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;OR&lt;/SPAN&gt; %&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt; condition &lt;SPAN style="color: #0000ff;"&gt;WHERE&lt;/SPAN&gt; a numeric&lt;/P&gt;&lt;P&gt;operand &lt;SPAN style="color: #0000ff;"&gt;IS&lt;/SPAN&gt; required. The condition was: &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.=&lt;SPAN style="color: #ff0000;"&gt;"IND"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ERROR: The macro TAPIS will stop executing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my macro:&lt;/P&gt;&lt;PRE __default_attr="html" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13860598621523759" jivemacro_uid="_13860598621523759" modifiedtitle="true"&gt;
&lt;P&gt;%macro tapis;&lt;/P&gt;
&lt;P&gt;data _null_; set tapis;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; CALL SYMPUT(COMPRESS("PARCOURS_"||_N_),PJC);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;data _null_; set tapis;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; CALL SYMPUT("Total",_n_);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;data tapis2; set tapis;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %do j=1 %to &amp;amp;TOTAL.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %put PARCOURS_&amp;amp;j. : &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %if &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.="IND" %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %put toto;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %tapis;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you help me? Thank you in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 08:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161927#M42114</guid>
      <dc:creator>sofisaas</dc:creator>
      <dc:date>2013-12-03T08:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: condition on a macro-variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161928#M42115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, my code doesn't appear clearly. Here it is again:&lt;/P&gt;&lt;P&gt;%macro tapis;&lt;/P&gt;&lt;P&gt;data _null_; set tapis;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CALL SYMPUT(COMPRESS("PARCOURS_"||_N_),PJC);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_; set tapis;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CALL SYMPUT("Total",_n_);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data tapis2; set tapis;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do j=1 %to &amp;amp;TOTAL.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put PARCOURS_&amp;amp;j. : &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.="IND" %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put toto;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%tapis;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 08:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161928#M42115</guid>
      <dc:creator>sofisaas</dc:creator>
      <dc:date>2013-12-03T08:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: condition on a macro-variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161929#M42116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well done on posting your code and the error message; a sample of data can also be helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To try and address the error message you are getting can you post what the log shows for:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%put PARCOURS_&amp;amp;j. : &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just before the error happens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it would be helpful for you to use obtain more information about the macro code when it is running by submitting the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;options mprint symbolgen mlogic;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;before you run your code, as it will provide more information in the log which could be helpful if posted here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are some other points of note about your code such as the macro do loop *not* needing to be in a data step, and the quotes around "IND" possibly not being necessary, but I doubt they will be causing the error you've reported. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For now, please supply what the &lt;SPAN style="font-family: 'courier new', courier;"&gt;%put&lt;/SPAN&gt; statement shows at the time of the error and / or the log when you use the options statement as that would be provide more information. Some sample data might also be useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 13:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161929#M42116</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-12-03T13:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: condition on a macro-variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161930#M42117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;%IF statement will throw that error if you end up with a value like AND or OR which it thinks as an operator, rather than just a text value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I added a data generation step below.&amp;nbsp; Your original code works until I add pjc="And". &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To fix it, I added macro quoting (see %BQUOTE on %IF statement), which will mask the meaning of AND, OR, etc, so that they are treated as a text string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;PRE&gt;%macro tapis;

%*Value AND below causes %eval to error from %IF statement ;
%*Unless use macro quoting;
data tapis;
&amp;nbsp; pjc="AAA"; output;
&amp;nbsp; pjc="IND"; output;
&amp;nbsp; pjc="And"; output; 
run;


data _null_; set tapis;
&amp;nbsp; CALL SYMPUT(COMPRESS("PARCOURS_"||_N_),PJC);
run;

 
 
data _null_; set tapis;
&amp;nbsp; CALL SYMPUT("Total",_n_);
run;

 
data tapis2; set tapis;
&amp;nbsp; %do j=1 %to &amp;amp;TOTAL.;
&amp;nbsp;&amp;nbsp;&amp;nbsp; %put PARCOURS_&amp;amp;j. : &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /*%if &amp;amp;&amp;amp;PARCOURS_&amp;amp;j.="IND" %then %do;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp; %if %bquote(&amp;amp;&amp;amp;PARCOURS_&amp;amp;j.)=IND %then %do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put toto;
&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;
&amp;nbsp; %end;
run;

%mend;

%tapis
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 13:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161930#M42117</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2013-12-03T13:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: condition on a macro-variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161931#M42118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Quentin has hit on the right issue.&amp;nbsp; But there is more than one possible approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that your macro variable contains the three characters IND.&amp;nbsp; It does not contain the five characters "IND".&amp;nbsp; So Quentin is right to remove the quotes when applying %BQUOTE.&amp;nbsp; However, you could also go the opposite route to make your program work. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, switch to CALL SYMPUTX to automatically remove leading or trailing blanks:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call symputx(..., PJC);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then use double quotes on both sides of the comparison:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if "&amp;amp;&amp;amp;PARCOURS_&amp;amp;j."="IND" %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's perhaps a simpler approach to solving the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 14:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161931#M42118</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-12-03T14:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: condition on a macro-variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161932#M42119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all very much for helping me. It works when I write %BQUOTE! Thanks again&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 14:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/condition-on-a-macro-variable/m-p/161932#M42119</guid>
      <dc:creator>sofisaas</dc:creator>
      <dc:date>2013-12-03T14:52:41Z</dc:date>
    </item>
  </channel>
</rss>

