<?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: Check Macro character variable value inside a %if condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567462#M159575</link>
    <description>&lt;P&gt;Thanks for replying. I tried both of them. None worked.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2019 21:30:54 GMT</pubDate>
    <dc:creator>dwights</dc:creator>
    <dc:date>2019-06-19T21:30:54Z</dc:date>
    <item>
      <title>Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567407#M159555</link>
      <description>&lt;P&gt;I'm trying to check the value of the character macro variable 'char_varzxy ' in a %if condition. The if loop is not being executed even if the condition holds true. Can someone please let me know why&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to &amp;amp;N;

/*&amp;nbsp; &amp;nbsp;Code to get the table&amp;nbsp; containing 'FLG' variable on which chi-square test is being run.
*
*
*
*
*/

&amp;nbsp; &amp;nbsp;

ods exclude all;
proc freq data=temp2 ORDER=formatted; 
tables &amp;amp;variable / TestP=(&amp;amp;P_Values); 
ods output OneWayFreqs=FreqOut OneWayChiSq=ChiSData;
output out=FreqStats N ChiSq;
run;
ods exclude none;

data ChiSqData2;
set ChiSData;
num_varu = input(cValue1,32.30);
char_varz= put(cValue1,12.8);

run;


proc sql noprint;
select nValue1 into :nValue1 from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;

proc sql noprint;
select num_varu into :num_vary from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;

proc sql noprint;
select cValue1 into :prob_vary from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;

proc sql noprint;
select char_varz into :char_varzxy from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;



%if(&amp;amp;char_varzxy ='&amp;lt;.0001') %then %do;

/*&amp;nbsp; &amp;nbsp; &amp;nbsp;Not entering this loop&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;

%end;

%end;



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The chisqdata2 table which contains the character variable is as follows -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Table&lt;/TD&gt;&lt;TD&gt;Name1&lt;/TD&gt;&lt;TD&gt;Label1&lt;/TD&gt;&lt;TD&gt;cValue1&lt;/TD&gt;&lt;TD&gt;nValue1&lt;/TD&gt;&lt;TD&gt;num_varu&lt;/TD&gt;&lt;TD&gt;char_varz&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Variable FLG&lt;/TD&gt;&lt;TD&gt;_PCHI_&lt;/TD&gt;&lt;TD&gt;Chi-Square&lt;/TD&gt;&lt;TD&gt;1246.522&lt;/TD&gt;&lt;TD&gt;1246.52212&lt;/TD&gt;&lt;TD&gt;1246.5221&lt;/TD&gt;&lt;TD&gt;1246.522&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Variable FLG&lt;/TD&gt;&lt;TD&gt;DF_PCHI&lt;/TD&gt;&lt;TD&gt;DF&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1.00E-30&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Variable FLG&lt;/TD&gt;&lt;TD&gt;P_PCHI&lt;/TD&gt;&lt;TD&gt;Pr &amp;gt; ChiSq&lt;/TD&gt;&lt;TD&gt;&amp;lt;.0001&lt;/TD&gt;&lt;TD&gt;4.73E-273&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;lt;.0001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 18:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567407#M159555</guid>
      <dc:creator>dwights</dc:creator>
      <dc:date>2019-06-19T18:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567414#M159556</link>
      <description>&lt;P&gt;Since the macro processor works with text only, quotes around strings are not needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;char_varzxy = &amp;lt;.0001 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "&amp;amp;char_varzxy" = "&amp;lt;.0001" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 19:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567414#M159556</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-19T19:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567416#M159558</link>
      <description>&lt;P&gt;If you do the following, what shows up?&lt;/P&gt;
&lt;PRE&gt;%PUT &amp;amp;char_varzxy;&lt;/PRE&gt;
&lt;P&gt;The variable may be numeric and the &amp;lt;0.001 is a formatted display so the value saved may be the exact value rather than the formatted value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268247"&gt;@dwights&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to check the value of the character macro variable 'char_varzxy ' in a %if condition. The if loop is not being executed even if the condition holds true. Can someone please let me know why&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to &amp;amp;N;

/*&amp;nbsp; &amp;nbsp;Code to get the table&amp;nbsp; containing 'FLG' variable on which chi-square test is being run.
*
*
*
*
*/

&amp;nbsp; &amp;nbsp;

ods exclude all;
proc freq data=temp2 ORDER=formatted; 
tables &amp;amp;variable / TestP=(&amp;amp;P_Values); 
ods output OneWayFreqs=FreqOut OneWayChiSq=ChiSData;
output out=FreqStats N ChiSq;
run;
ods exclude none;

data ChiSqData2;
set ChiSData;
num_varu = input(cValue1,32.30);
char_varz= put(cValue1,12.8);

run;


proc sql noprint;
select nValue1 into :nValue1 from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;

proc sql noprint;
select num_varu into :num_vary from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;

proc sql noprint;
select cValue1 into :prob_vary from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;

proc sql noprint;
select char_varz into :char_varzxy from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';
quit;



%if(&amp;amp;char_varzxy ='&amp;lt;.0001') %then %do;

/*&amp;nbsp; &amp;nbsp; &amp;nbsp;Not entering this loop&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;

%end;

%end;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The chisqdata2 table which contains the character variable is as follows -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Table&lt;/TD&gt;
&lt;TD&gt;Name1&lt;/TD&gt;
&lt;TD&gt;Label1&lt;/TD&gt;
&lt;TD&gt;cValue1&lt;/TD&gt;
&lt;TD&gt;nValue1&lt;/TD&gt;
&lt;TD&gt;num_varu&lt;/TD&gt;
&lt;TD&gt;char_varz&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Variable FLG&lt;/TD&gt;
&lt;TD&gt;_PCHI_&lt;/TD&gt;
&lt;TD&gt;Chi-Square&lt;/TD&gt;
&lt;TD&gt;1246.522&lt;/TD&gt;
&lt;TD&gt;1246.52212&lt;/TD&gt;
&lt;TD&gt;1246.5221&lt;/TD&gt;
&lt;TD&gt;1246.522&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Variable FLG&lt;/TD&gt;
&lt;TD&gt;DF_PCHI&lt;/TD&gt;
&lt;TD&gt;DF&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1.00E-30&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Variable FLG&lt;/TD&gt;
&lt;TD&gt;P_PCHI&lt;/TD&gt;
&lt;TD&gt;Pr &amp;gt; ChiSq&lt;/TD&gt;
&lt;TD&gt;&amp;lt;.0001&lt;/TD&gt;
&lt;TD&gt;4.73E-273&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;&amp;lt;.0001&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 19:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567416#M159558</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-19T19:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567419#M159559</link>
      <description>&lt;PRE&gt;It prints the following -&lt;BR /&gt;&lt;BR /&gt;char_varzxy = &lt;SPAN&gt;&amp;lt;.0001&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 19:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567419#M159559</guid>
      <dc:creator>dwights</dc:creator>
      <dc:date>2019-06-19T19:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567422#M159560</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268247"&gt;@dwights&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;It prints the following -&lt;BR /&gt;&lt;BR /&gt;char_varzxy = &lt;SPAN&gt;&amp;lt;.0001&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;See? No quotes.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 19:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567422#M159560</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-19T19:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567462#M159575</link>
      <description>&lt;P&gt;Thanks for replying. I tried both of them. None worked.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 21:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567462#M159575</guid>
      <dc:creator>dwights</dc:creator>
      <dc:date>2019-06-19T21:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567489#M159585</link>
      <description>&lt;P&gt;I don't see any code where you are putting single quotes into the value of the macro variable. Unless that is what the ODS output does, but I doubt that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do appear to be putting trailing spaces into the value of the macro variable however.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select char_varz into :char_varzxy from ChiSqData2 where Label1='Pr &amp;gt; ChiSq';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either remove the trailing spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let char_varzxy=&amp;amp;char_varzxy;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or don't put them into the value to begin with by adding the TRIMMED keyword to the INTO clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select char_varz
  into :char_varzxy trimmed
from ChiSqData2 
where Label1='Pr &amp;gt; ChiSq'
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because your macro variable contains &amp;lt; you should use quoting to avoid confusing SAS about what test you are doing. It is probably easier to use actual quotes instead of macro quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "&amp;lt;.0001" = "&amp;amp;char_varzxy" %then ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure to use double quote character and not single quote character because macro variable references are not resolved inside of single quotes.&amp;nbsp; Make sure both sides use the same quote character.&amp;nbsp; A single quote character is not equal to a double quote character.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 00:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567489#M159585</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-20T00:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567490#M159586</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;That test will not reveal leading/trailing spaces.&lt;/P&gt;
&lt;P&gt;Use something like this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%PUT |&amp;amp;char_varzxy|;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 00:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567490#M159586</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-20T00:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Check Macro character variable value inside a %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567644#M159649</link>
      <description>&lt;P&gt;Thank you very much! The trimmed keyword and the double quotes helped me.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 15:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567644#M159649</guid>
      <dc:creator>dwights</dc:creator>
      <dc:date>2019-06-20T15:01:22Z</dc:date>
    </item>
  </channel>
</rss>

