<?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: SAS macro error - character operand was found... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-error-character-operand-was-found/m-p/799572#M314424</link>
    <description>&lt;P&gt;The variable named &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt; is a DATA step variable. The %EVAL function cannot operate on data step variables, it only accepts macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whenever you write macro or macro variable code, you FIRST need to obtain working valid legal SAS code for one instance without macros and without macro variables. If you can't get the code to work without macros and without macro variables, it will never work with macros and with macro variables. In this case, your statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var(4*(i-1)+j) = (test&amp;amp;CY.&amp;amp;CQ.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not valid legal SAS code in this data step as written, even if you remove both macro variables, because the left hand side of the equation will cause an error. Also variables whose name begin with TEST are undefined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should probably re-write this entirely as DATA step code with no macros or macro variables. This can be done via ARRAYs in your DATA step. You should also re-write the code to use valid SAS date values to represent quarters, rather than developing your own arithmetic to obtain and manipulate quarters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;People usually ignore the advice to write working valid legal SAS code without macros first. But if you don't do that, I don't see how any progress can be made. Don't ignore the advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, I'll even do the easy part for you, this is your code without macros and without macro variables. Now, you make it into working valid legal SAS code that does what you want. (Becuase it doesn't work right now, and I have no idea what you are trying to do)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
do i = 1 to 5;
	do j = 1 to 4;
		if 1-j &amp;lt;= 0 then do;
			CY = 2022.-i;
			CQ = 1-j+4;
			var(4*(i-1)+j) = (test20221);
			end;

		else do;
			CY = 2022-(i-1);
			CQ = 1-j;
			var(4*(i-1)+j) = (test20221);
			end;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2022 14:59:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-03-02T14:59:00Z</dc:date>
    <item>
      <title>SAS macro error - character operand was found...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-error-character-operand-was-found/m-p/799570#M314423</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create macro variable within if else condition.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an error:&amp;nbsp;&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;BR /&gt;2022-i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%LET year = 2022;
%LET qtr = 1;

data test;
do i = 1 to 5;
	do j = 1 to 4;
/*qtr is 1*/
/*when j = 1, prefer to run following if condition*/
		if &amp;amp;qtr.-j &amp;lt;= 0 then do;
/*			create macro variable CY (year - i value)*/
/*			create macro variable CQ (qtr - j = 4 value)*/
			%let CY = %eval(&amp;amp;year.-i);
			%let CQ = %eval(&amp;amp;qtr.-j+4);
			var(4*(i-1)+j) = (test&amp;amp;CY.&amp;amp;CQ.);
			end;

		else do;
			%let CY = %eval(&amp;amp;year.-(i-1));
			%let CQ = %eval(&amp;amp;qtr.-j);
			var(4*(i-1)+j) = (test&amp;amp;CY.&amp;amp;CQ.);
			end;
		end;
	end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Mar 2022 14:28:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-error-character-operand-was-found/m-p/799570#M314423</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-03-02T14:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro error - character operand was found...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-error-character-operand-was-found/m-p/799572#M314424</link>
      <description>&lt;P&gt;The variable named &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt; is a DATA step variable. The %EVAL function cannot operate on data step variables, it only accepts macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whenever you write macro or macro variable code, you FIRST need to obtain working valid legal SAS code for one instance without macros and without macro variables. If you can't get the code to work without macros and without macro variables, it will never work with macros and with macro variables. In this case, your statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var(4*(i-1)+j) = (test&amp;amp;CY.&amp;amp;CQ.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not valid legal SAS code in this data step as written, even if you remove both macro variables, because the left hand side of the equation will cause an error. Also variables whose name begin with TEST are undefined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should probably re-write this entirely as DATA step code with no macros or macro variables. This can be done via ARRAYs in your DATA step. You should also re-write the code to use valid SAS date values to represent quarters, rather than developing your own arithmetic to obtain and manipulate quarters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;People usually ignore the advice to write working valid legal SAS code without macros first. But if you don't do that, I don't see how any progress can be made. Don't ignore the advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, I'll even do the easy part for you, this is your code without macros and without macro variables. Now, you make it into working valid legal SAS code that does what you want. (Becuase it doesn't work right now, and I have no idea what you are trying to do)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
do i = 1 to 5;
	do j = 1 to 4;
		if 1-j &amp;lt;= 0 then do;
			CY = 2022.-i;
			CQ = 1-j+4;
			var(4*(i-1)+j) = (test20221);
			end;

		else do;
			CY = 2022-(i-1);
			CQ = 1-j;
			var(4*(i-1)+j) = (test20221);
			end;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 14:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-error-character-operand-was-found/m-p/799572#M314424</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-02T14:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro error - character operand was found...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-error-character-operand-was-found/m-p/799580#M314427</link>
      <description>&lt;P&gt;Write this down and stick it to your monitor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The macro PREprocessor does its work with code before that code is sent to the SAS interpreter.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the %LET statements are resolved BEFORE your data step code is sent to the data step compiler, therefore your "inner" (which are, as you will see, not "in" the data step at all) %LETs are resolved with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CY = %eval(2022-i);
%let CQ = %eval(1-j+4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, neither the letter i nor the letter j are numeric in any way, and that is why the macro preprocessor complains.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can only &lt;EM&gt;create&lt;/EM&gt; data step code with the macro processor, but you cannot &lt;EM&gt;use&lt;/EM&gt; it (with the exception of data step functions in a %SYFUNC, but these are then also evaluated at macro resolve time, not at code execution time).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 15:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-error-character-operand-was-found/m-p/799580#M314427</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-02T15:01:41Z</dc:date>
    </item>
  </channel>
</rss>

