<?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: SELECT INTO numerical variable evaluation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33302#M6487</link>
    <description>Just to expand on RickM's answer a bit.  &lt;BR /&gt;
&lt;BR /&gt;
The %IF statement:&lt;BR /&gt;
&lt;BR /&gt;
[pre]%if &amp;amp;x lt 9 %then.....&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
will perform a numeric comparison if &amp;amp;x contains an integer (there is an implied %EVAL), but a alphabetic comparison if either side is a noninteger.  Since the decimal point makes for a noninteger  10.0 lt 9 is true, while 10 lt 9 is false.  The %sysevalf forces a numeric comparison.

those darn lt signs &lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: ArtC</description>
    <pubDate>Fri, 12 Nov 2010 22:09:59 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2010-11-12T22:09:59Z</dc:date>
    <item>
      <title>SELECT INTO numerical variable evaluation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33299#M6484</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
This seems like a simple problem. When uses the SELECT INTO clause I end up with  a character variable than cannot be evaluated numerically. How can this be modified to resolve the evaluation correctly?&lt;BR /&gt;
&lt;BR /&gt;
%macro t;&lt;BR /&gt;
	PROC SQL NOPRINT;&lt;BR /&gt;
		Select t1.AVG_Denom  into :xAvgDenom&lt;BR /&gt;
		From WORK.testdata2 as t1;&lt;BR /&gt;
	;&lt;BR /&gt;
	%put Average is &amp;amp;xAvgDenom;&lt;BR /&gt;
	%if &amp;amp;xAvgDenom &amp;lt; 25 %then&lt;BR /&gt;
	 %put &amp;amp;xAvgDenom is Less Than 25;&lt;BR /&gt;
	%else&lt;BR /&gt;
	 %put &amp;amp;xAvgDenom is Greater Than 25;&lt;BR /&gt;
	;&lt;BR /&gt;
%_eg_conditional_dropds(testdata2)&lt;BR /&gt;
%mend t;&lt;BR /&gt;
OPTIONS Nomlogic;&lt;BR /&gt;
	Data testdata2;&lt;BR /&gt;
	input AVG_Denom;&lt;BR /&gt;
	;&lt;BR /&gt;
	cards;&lt;BR /&gt;
	112.4118	;&lt;BR /&gt;
&lt;BR /&gt;
%t;&lt;BR /&gt;
&lt;BR /&gt;
Average is 112.4118&lt;BR /&gt;
112.4118 is Less Than 25 (not in my way of thinking)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thank you in advance,&lt;BR /&gt;
John</description>
      <pubDate>Fri, 12 Nov 2010 19:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33299#M6484</guid>
      <dc:creator>khill</dc:creator>
      <dc:date>2010-11-12T19:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO numerical variable evaluation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33300#M6485</link>
      <description>Hello Khill,&lt;BR /&gt;
&lt;BR /&gt;
The problem with your code is that all macro %IFs are resolved at compilation phase when AVG_Denom is not yet accessible. Reducing %IFs to datastep IFs solves the problem:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro t;&lt;BR /&gt;
proc SQL noprint;&lt;BR /&gt;
  select t1.AVG_Denom into :xAvgDenom&lt;BR /&gt;
  from WORK.testdata2 as t1&lt;BR /&gt;
;quit;&lt;BR /&gt;
%put Average is &amp;amp;xAvgDenom;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  if &amp;amp;xAvgDenom &amp;lt; 25 then put "&amp;amp;xAvgDenom is Less Than 25";&lt;BR /&gt;
  else put "&amp;amp;xAvgDenom is Greater Than 25";&lt;BR /&gt;
run;&lt;BR /&gt;
%mend t;&lt;BR /&gt;
%t;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Fri, 12 Nov 2010 20:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33300#M6485</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-11-12T20:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO numerical variable evaluation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33301#M6486</link>
      <description>Try using &lt;BR /&gt;
&lt;BR /&gt;
%put Average is &amp;amp;xAvgDenom;&lt;BR /&gt;
%if %sysevalf(&amp;amp;xAvgDenom &amp;lt; 25) %then&lt;BR /&gt;
%put &amp;amp;xAvgDenom is Less Than 25;&lt;BR /&gt;
%else&lt;BR /&gt;
%put &amp;amp;xAvgDenom is Greater Than 25;&lt;BR /&gt;
&lt;BR /&gt;
Remember that macro variables are considered text so if you are doing any sort of numeric operation (addition, subtraction, boolean comparison) you need to use %eval (for integers) or %sysevalf (for floating point numbers).&lt;BR /&gt;
&lt;BR /&gt;
Good luck!</description>
      <pubDate>Fri, 12 Nov 2010 20:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33301#M6486</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-11-12T20:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO numerical variable evaluation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33302#M6487</link>
      <description>Just to expand on RickM's answer a bit.  &lt;BR /&gt;
&lt;BR /&gt;
The %IF statement:&lt;BR /&gt;
&lt;BR /&gt;
[pre]%if &amp;amp;x lt 9 %then.....&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
will perform a numeric comparison if &amp;amp;x contains an integer (there is an implied %EVAL), but a alphabetic comparison if either side is a noninteger.  Since the decimal point makes for a noninteger  10.0 lt 9 is true, while 10 lt 9 is false.  The %sysevalf forces a numeric comparison.

those darn lt signs &lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: ArtC</description>
      <pubDate>Fri, 12 Nov 2010 22:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33302#M6487</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-11-12T22:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT INTO numerical variable evaluation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33303#M6488</link>
      <description>Rick and Art, thanks for the insight. This is what I needed to get me back on track.&lt;BR /&gt;
&lt;BR /&gt;
John</description>
      <pubDate>Sat, 13 Nov 2010 01:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-INTO-numerical-variable-evaluation/m-p/33303#M6488</guid>
      <dc:creator>khill</dc:creator>
      <dc:date>2010-11-13T01:32:15Z</dc:date>
    </item>
  </channel>
</rss>

