<?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 variable usage in macro conditions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623625#M19963</link>
    <description>&lt;P&gt;One thing to keep in mind: MACRO VARIABLES ARE ALWAYS TEXT.&lt;/P&gt;
&lt;P&gt;So comparisons will be done like text comparisons: first character to first character, second&amp;nbsp;to second and so,&amp;nbsp;and the first difference setting the inequality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to compare character strings that contain decimal values then you need to wrap the comparison&amp;nbsp;in %sysevalf, to evaluate&amp;nbsp;the &amp;nbsp;floating point (decimal) values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro chk();

/*The prow values are obtained by using PROC SQL SELECT INTO but below are displayed for example purpose*/

%let prow1 = 13.23529;

%let prow2 = 5.714286;

%put prow1, prow2 ==&amp;gt; &amp;amp;prow1. , &amp;amp;prow2.;


%if %sysevalf(&amp;amp;prow1. &amp;gt;  &amp;amp;prow2.) %then %do;

	data chk;
		a = "&amp;amp;prow1. &amp;gt; &amp;amp;prow2.";
	run;

	proc print data=chk;
	run;

%end;
%if %sysevalf(&amp;amp;prow2. &amp;gt; &amp;amp;prow1.) %then %do;

	data chk2;
		a = "&amp;amp;prow2. &amp;gt; &amp;amp;prow1.";
	run;

	proc print data=chk2;
	run;

%end;

%mend chk;
&lt;/PRE&gt;</description>
    <pubDate>Mon, 10 Feb 2020 16:57:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-02-10T16:57:45Z</dc:date>
    <item>
      <title>Macro variable usage in macro conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623619#M19960</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Getting an issue when using macro variable in macro condition. This code works if the macro variable values are whole numbers but if the values contain decimal values then SAS does not process the conditions correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the below example, prow1 value is greater than prow2 value but somehow SAS is doing %IF condition &amp;amp;prow2. &amp;gt; &amp;amp;prow1. is TRUE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help to identify issue and provide a resolution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;options mlogic mprint;


%macro chk;

/*The prow values are obtained by using PROC SQL SELECT INTO but below are displayed for example purpose*/

%let prow1 = 13.23529;

%let prow2 = 5.714286;

%put prow1, prow2 ==&amp;gt; &amp;amp;prow1. , &amp;amp;prow2.;


%if &amp;amp;prow1. &amp;gt; &amp;amp;prow2. %then %do;

	data chk;
		a = "&amp;amp;prow1. &amp;gt; &amp;amp;prow2.";
	run;

	proc print data=chk;
	run;

%end;



%if &amp;amp;prow2. &amp;gt; &amp;amp;prow1. %then %do;

	data chk2;
		a = "&amp;amp;prow2. &amp;gt; &amp;amp;prow1.";
	run;

	proc print data=chk2;
	run;

%end;

%mend chk;


%chk;


&lt;/PRE&gt;&lt;P&gt;And here is the LOG for above code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;MLOGIC(CHK):  Beginning execution.
MLOGIC(CHK):  %LET (variable name is PROW1)
MLOGIC(CHK):  %LET (variable name is PROW2)
MLOGIC(CHK):  %PUT prow1, prow2 ==&amp;gt; &amp;amp;prow1. , &amp;amp;prow2.
prow1, prow2 ==&amp;gt; 13.23529 , 5.714286
MLOGIC(CHK):  %IF condition &amp;amp;prow1. &amp;gt; &amp;amp;prow2. is FALSE
MLOGIC(CHK):  %IF condition &amp;amp;prow2. &amp;gt; &amp;amp;prow1. is TRUE
MPRINT(CHK):   data chk2;
MPRINT(CHK):   a = "5.714286 &amp;gt; 13.23529";
MPRINT(CHK):   run;

NOTE: The data set WORK.CHK2 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

MPRINT(CHK):   proc print data=chk2;
MPRINT(CHK):   run;

NOTE: There were 1 observations read from the data set WORK.CHK2.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623619#M19960</guid>
      <dc:creator>tanmaykhole208</dc:creator>
      <dc:date>2020-02-10T16:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable usage in macro conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623621#M19961</link>
      <description>&lt;P&gt;You need %SYSEVALF to evaluate floats&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%if %sysevalf(&amp;amp;prow1. &amp;gt; &amp;amp;prow2.) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623621#M19961</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-10T16:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable usage in macro conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623622#M19962</link>
      <description>&lt;P&gt;The implicit %EVAL() function call used by %IF does not do floating point.&amp;nbsp; So it will treat your example values as strings to be compared.&amp;nbsp; Use %SYSEVALF() instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysevalf(&amp;amp;prow1. &amp;gt; &amp;amp;prow2.) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623622#M19962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-10T16:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable usage in macro conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623625#M19963</link>
      <description>&lt;P&gt;One thing to keep in mind: MACRO VARIABLES ARE ALWAYS TEXT.&lt;/P&gt;
&lt;P&gt;So comparisons will be done like text comparisons: first character to first character, second&amp;nbsp;to second and so,&amp;nbsp;and the first difference setting the inequality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to compare character strings that contain decimal values then you need to wrap the comparison&amp;nbsp;in %sysevalf, to evaluate&amp;nbsp;the &amp;nbsp;floating point (decimal) values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro chk();

/*The prow values are obtained by using PROC SQL SELECT INTO but below are displayed for example purpose*/

%let prow1 = 13.23529;

%let prow2 = 5.714286;

%put prow1, prow2 ==&amp;gt; &amp;amp;prow1. , &amp;amp;prow2.;


%if %sysevalf(&amp;amp;prow1. &amp;gt;  &amp;amp;prow2.) %then %do;

	data chk;
		a = "&amp;amp;prow1. &amp;gt; &amp;amp;prow2.";
	run;

	proc print data=chk;
	run;

%end;
%if %sysevalf(&amp;amp;prow2. &amp;gt; &amp;amp;prow1.) %then %do;

	data chk2;
		a = "&amp;amp;prow2. &amp;gt; &amp;amp;prow1.";
	run;

	proc print data=chk2;
	run;

%end;

%mend chk;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623625#M19963</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-10T16:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable usage in macro conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623626#M19964</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623626#M19964</guid>
      <dc:creator>tanmaykhole208</dc:creator>
      <dc:date>2020-02-10T16:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable usage in macro conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623627#M19965</link>
      <description>Thank you, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;!</description>
      <pubDate>Mon, 10 Feb 2020 16:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623627#M19965</guid>
      <dc:creator>tanmaykhole208</dc:creator>
      <dc:date>2020-02-10T16:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable usage in macro conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623628#M19966</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 17:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-variable-usage-in-macro-conditions/m-p/623628#M19966</guid>
      <dc:creator>tanmaykhole208</dc:creator>
      <dc:date>2020-02-10T17:00:08Z</dc:date>
    </item>
  </channel>
</rss>

