<?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: How to use the loop number as numeric operand? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434857#M28098</link>
    <description>&lt;P&gt;The macro functions are evaluated while the data step code is fetched for compilation, and see i as text and not as a variable name.&lt;/P&gt;
&lt;P&gt;Don't use macro statements for actions that should happen when the data step runs.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2018 14:16:00 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-02-07T14:16:00Z</dc:date>
    <item>
      <title>How to use the loop number as numeric operand?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434849#M28094</link>
      <description>&lt;P&gt;Good day everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm&amp;nbsp;trying to write a code&amp;nbsp;to automaticly group a variable in predefined buckets. In a last step I want to name the value (bucket name)&amp;nbsp;based on the loop number, but somehow I'm not able to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code of this last step&amp;nbsp;is as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
set Have;

/* If the observation has no bucket yet proceed to actions */
IF &amp;amp;Bucket.='' THEN DO;

	/* Go through as many loops as there are buckets */
	DO i=1 TO (2+(&amp;amp;MinValue.+&amp;amp;MaxValue.)/&amp;amp;Step.)-2;
		
		/* If the value is &amp;gt; the minimum value of the bucket and &amp;lt;= the max value, then this should be the bucket*/
		IF &amp;amp;Value. &amp;gt; &amp;amp;MinValue.+(i-1)*&amp;amp;Step. AND &amp;amp;Value. &amp;lt;= &amp;amp;MinValue.+ i*&amp;amp;Step. THEN 
			
			DO;	/* If the bucket number is &amp;lt; 10 use 00 as a prefix, &amp;lt;100 use 0 as a prefix and otherwise use no prefix */
				IF i + 1 &amp;lt; 10 THEN &amp;amp;Bucket.= "00%SYSEVALF(i+1). &amp;gt; %SYSEVALF(&amp;amp;MinValue.+(i-1)*&amp;amp;Step.) and &amp;lt;= %SYSEVALF(&amp;amp;MinValue.+i*&amp;amp;Step.)";

				IF i + 1 &amp;gt;= 10 and i+1 &amp;lt; 100 THEN &amp;amp;Bucket.= "0%SYSEVALF(i+1). &amp;gt; %SYSEVALF(&amp;amp;MinValue.+(i-1)*&amp;amp;Step.) and &amp;lt;= %SYSEVALF(&amp;amp;MinValue.+i*&amp;amp;Step.)";

				IF i + 1 &amp;gt;= 100 THEN &amp;amp;Bucket.= "%SYSEVALF(i+1). &amp;gt; %SYSEVALF(&amp;amp;MinValue.+(i-1)*&amp;amp;Step.) and &amp;lt;= %SYSEVALF(&amp;amp;MinValue.+i*&amp;amp;Step.)";
			END;
	END;
END;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;FONT face="Consolas" size="2"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"00%SYSEVALF(&amp;amp;i.+1). &amp;gt; %SYSEVALF(&amp;amp;MinValue.+(&amp;amp;i.-1)*&amp;amp;Step.) and &amp;lt;= %SYSEVALF(&amp;amp;MinValue.+&amp;amp;i.*&amp;amp;Step.)";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Should result in: "002. &amp;gt; 0 and &amp;lt;= 10" if &amp;amp;Value. equals a number between 0 and 10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However SAS doesn't treat "i" as a numeric value in the generation of the result, but as the character i. So the %SYSEVALF() function doesn't work.:&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;/P&gt;&lt;P&gt;i+1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS does treat "i" as a numeric operand in the prior IF statement. I'm confused. Is there a solution for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Maxim&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 13:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434849#M28094</guid>
      <dc:creator>MaximB91</dc:creator>
      <dc:date>2018-02-07T13:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the loop number as numeric operand?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434853#M28096</link>
      <description>&lt;P&gt;First off, why all the macro code?&amp;nbsp; All that macro code in there is irrelevant - you can do these things in straight datastep - and it is also not explained, What is &amp;amp;Bucket. ?&lt;/P&gt;
&lt;P&gt;Secondly why not use the procedure written to do this kind of thing;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p0le3p5ngj1zlbn1mh3tistq9t76.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p0le3p5ngj1zlbn1mh3tistq9t76.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434853#M28096</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-07T14:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the loop number as numeric operand?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434855#M28097</link>
      <description>&lt;P&gt;You have correctly identified the problem.&amp;nbsp; Here's one way to approach a solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;bucket. = catx(' ', put(i, z3.), '&amp;gt;', &amp;amp;MinValue.+(i-1)*&amp;amp;Step., 'and&amp;nbsp;&amp;lt;=' ,&amp;amp;MinValue.+i*&amp;amp;Step.)&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is conceivable that you need to tweak this, since the values for &amp;amp;MinValue and &amp;amp;Step are constant for the duration of the DATA step.&amp;nbsp; However, the formulas might work just as they are ... just one way to find out.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434855#M28097</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T14:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the loop number as numeric operand?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434857#M28098</link>
      <description>&lt;P&gt;The macro functions are evaluated while the data step code is fetched for compilation, and see i as text and not as a variable name.&lt;/P&gt;
&lt;P&gt;Don't use macro statements for actions that should happen when the data step runs.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434857#M28098</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-07T14:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the loop number as numeric operand?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434882#M28103</link>
      <description>Thank you! This actually works. I tweaked it to:&lt;BR /&gt;&amp;amp;Bucket. = cat('00',i+1,'.',' &amp;gt; ', &amp;amp;MinValue.+(i-1)*&amp;amp;Step., ' and &amp;lt;= ' ,&amp;amp;MinValue.+i*&amp;amp;Step.);</description>
      <pubDate>Wed, 07 Feb 2018 15:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434882#M28103</guid>
      <dc:creator>MaximB91</dc:creator>
      <dc:date>2018-02-07T15:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the loop number as numeric operand?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434885#M28104</link>
      <description>&lt;P&gt;Glad it's working.&amp;nbsp; I hope you checked out the Z3 format.&amp;nbsp; It means you might need just one formula instead of 3 formulas for different ranges.&amp;nbsp; Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;Bucket. = cat( put(i+1,z3.) || '.',' &amp;gt; ', &amp;amp;MinValue.+(i-1)*&amp;amp;Step., ' and &amp;lt;= ' ,&amp;amp;MinValue.+i*&amp;amp;Step.);&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 15:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/434885#M28104</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T15:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the loop number as numeric operand?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/435174#M28146</link>
      <description>&lt;P&gt;This works even better. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 07:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-use-the-loop-number-as-numeric-operand/m-p/435174#M28146</guid>
      <dc:creator>MaximB91</dc:creator>
      <dc:date>2018-02-08T07:29:48Z</dc:date>
    </item>
  </channel>
</rss>

