<?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: The %TO value of the %DO I loop is invalid in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884853#M39275</link>
    <description>&lt;P&gt;Simple enough to analyze.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start with the error.&amp;nbsp; The only way &amp;amp;DIF is not value is if the result of the function call that created it is a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So look at the arguments to that function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dif = %sysfunc(intck(MONTH,&amp;amp;startdate,&amp;amp;enddate)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first one is fine.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So where did those two macro variable get created?&amp;nbsp; There are two choices, but they both follow the same (incorrect) pattern.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin = put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -6), date9.);
%let end = put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -1), date9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The answer is obvious. You are setting BEGIN and END to strings that start with the letters PUT.&amp;nbsp; Those cannot be a valid number to pass to the INTNX() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You clearly understand that you have to use %SYSFUNC() to call SAS functions in macro code because you used it when trying to make the macro variable DIF.&amp;nbsp; So you need to use it when making BEGIN and END also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin = %sysfunc(intnx(month,%sysfunc(inputN(&amp;amp;period.01,yymmdd10.)),-6));
%let end = %sysfunc(intnx(month,&amp;amp;begin,+5));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do not FORMAT the values with the DATE9. format if the goal is to use them as DATE values (and not text strings for humans to read).&amp;nbsp; But if you did set the macro variables to strings like 01JAN2023 then to use them as actual date values you would need to add quotes and the letter D to create date literals.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin = "%sysfunc(intnx(month,%sysfunc(inputN(&amp;amp;period.01,yymmdd10.)),-6),date9.)"d;
%let end = "%sysfunc(intnx(month,&amp;amp;begin,+5),date9.)"d;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Jul 2023 18:40:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-07-14T18:40:33Z</dc:date>
    <item>
      <title>The %TO value of the %DO I loop is invalid</title>
      <link>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884849#M39274</link>
      <description>&lt;P&gt;Hi all, i have write the macro as shown below.&lt;/P&gt;&lt;P&gt;Initially, I direct put the begin date and end date &lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;EM&gt;(example stated in orange font below)&lt;/EM&gt;&lt;/FONT&gt;. The macro manages to run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, for ease of efficiency in future, I would like to set a formula to indicate the begin date and end date.&amp;nbsp; But, it pops the error as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       &amp;amp;dif 
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro DATECREATE will stop executing.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let Period = 202304;
%let Month  = 4;

%macro month_setting();
    %global begin end;

    %if %sysevalf(&amp;amp;month = 4) %then 
        %do;		
	    %let begin		= put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -6), date9.);
	    %let end		= put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -1), date9.);
&lt;FONT color="#FF6600"&gt;/*	    %let begin 		= 01OCT2022;*/
/*	    %let end 		= 01APR2023;*/&lt;/FONT&gt;
        %end;
	%else %if %sysevalf(&amp;amp;month = 13) %then
        %do;
	    %let begin		= put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -13), date9.);
	    %let end		= put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -1), date9.);
&lt;FONT color="#FF6600"&gt;/*	    %let begin 		= 01JAN2022;*/
/*	    %let end 		= 01APR2023;*/&lt;/FONT&gt;
        %end;

%mend month_setting;
%month_setting();

%macro datecreate;
	%let startdate  = %sysfunc(inputn(&amp;amp;begin,anydtdte9.));
	%let enddate	= %sysfunc(inputn(&amp;amp;end,anydtdte9.));
	%let dif	= %sysfunc(intck(MONTH,&amp;amp;startdate,&amp;amp;enddate)); 
		%do i=0 %to &amp;amp;dif;
			%global date_&amp;amp;i;
			%let date_&amp;amp;i=%sysfunc(intnx(month,&amp;amp;startdate,&amp;amp;i,B),yymmn6.);
			%put &amp;amp;&amp;amp;date_&amp;amp;i;
		%end;
%mend;
%datecreate;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Would like to seek for help to solve the issue. Thanks in advance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 18:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884849#M39274</guid>
      <dc:creator>Michelle_</dc:creator>
      <dc:date>2023-07-14T18:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: The %TO value of the %DO I loop is invalid</title>
      <link>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884853#M39275</link>
      <description>&lt;P&gt;Simple enough to analyze.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start with the error.&amp;nbsp; The only way &amp;amp;DIF is not value is if the result of the function call that created it is a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So look at the arguments to that function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dif = %sysfunc(intck(MONTH,&amp;amp;startdate,&amp;amp;enddate)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first one is fine.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So where did those two macro variable get created?&amp;nbsp; There are two choices, but they both follow the same (incorrect) pattern.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin = put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -6), date9.);
%let end = put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -1), date9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The answer is obvious. You are setting BEGIN and END to strings that start with the letters PUT.&amp;nbsp; Those cannot be a valid number to pass to the INTNX() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You clearly understand that you have to use %SYSFUNC() to call SAS functions in macro code because you used it when trying to make the macro variable DIF.&amp;nbsp; So you need to use it when making BEGIN and END also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin = %sysfunc(intnx(month,%sysfunc(inputN(&amp;amp;period.01,yymmdd10.)),-6));
%let end = %sysfunc(intnx(month,&amp;amp;begin,+5));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do not FORMAT the values with the DATE9. format if the goal is to use them as DATE values (and not text strings for humans to read).&amp;nbsp; But if you did set the macro variables to strings like 01JAN2023 then to use them as actual date values you would need to add quotes and the letter D to create date literals.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin = "%sysfunc(intnx(month,%sysfunc(inputN(&amp;amp;period.01,yymmdd10.)),-6),date9.)"d;
%let end = "%sysfunc(intnx(month,&amp;amp;begin,+5),date9.)"d;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2023 18:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884853#M39275</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T18:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: The %TO value of the %DO I loop is invalid</title>
      <link>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884856#M39276</link>
      <description>&lt;P&gt;&amp;amp;begin will resolve to the text&lt;/P&gt;
&lt;PRE&gt;put(intnx('month',input(strip(put(&amp;amp;period, 6.)||'01'), yymmdd10.), -6), date9.)&lt;/PRE&gt;
&lt;P&gt;which can not be used as argument for the INPUTN function. Similar for &amp;amp;end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always keep in mind that a DATA step function will only work in macro language when wrapped in %SYSFUNC.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 18:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884856#M39276</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-14T18:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: The %TO value of the %DO I loop is invalid</title>
      <link>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884899#M39280</link>
      <description>&lt;P&gt;It works! Thank you so much.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2023 06:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/The-TO-value-of-the-DO-I-loop-is-invalid/m-p/884899#M39280</guid>
      <dc:creator>Michelle_</dc:creator>
      <dc:date>2023-07-15T06:33:09Z</dc:date>
    </item>
  </channel>
</rss>

