<?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: INTCK Invalid Value in Macro Function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717977#M222116</link>
    <description>&lt;P&gt;%LET is not a sas data step statement but a declarative one to be coded out of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should use next code instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testing;
    set subdata;
       lastdate = input('20201201',yymmdd8.);
       monthdiff= INTCK(MONTH,date1,lastdate);
       t0='m' || monthdiff;
       t1='m' || monthdiff-1;
       t2='m' || monthdiff-2;
       t3='m' || monthdiff-3;
       t4='m' || monthdiff-4;
       t5='m' || monthdiff-5;
       t6='m' || monthdiff-6;
     ..........&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thus can be shorten by using an array and a do loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testing;
    set subdata;
       lastdate = inputn(20201201,yymmdd8.);
       monthdiff= INTCK(MONTH,date1,lastdate);
	   
	   array tx {} T0-T6;  /* or Tn where n is the last one */
	   do i=0 to dim(tx);
	      tx(i) = monthdiff - i;
	   end;
/***	   
       t0='m' || monthdiff;
       t1='m' || monthdiff-1;
       t2='m' || monthdiff-2;
       t3='m' || monthdiff-3;
       t4='m' || monthdiff-4;
       t5='m' || monthdiff-5;
       t6='m' || monthdiff-6;
***/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need the Tn macro variables for future use than the right function is CALL SYMPUT as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	   do i=0 to dim(tx);
	      tx(i) = monthdiff - i;
             call symput(vname(tx(i)) , tx(i));
	   end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Feb 2021 19:00:15 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-02-09T19:00:15Z</dc:date>
    <item>
      <title>INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717967#M222110</link>
      <description>&lt;P&gt;I first created the dataset as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data subdata;
    set storage.data1;
    date1 = input(a_dt, yymmdd10.);
    date2=input(b_dt,yymmdd10.);
    format date1 date2 yymmn6.;
    if date1 ge "01Jan2018"d;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The dataset is set up so there's a bunch of columns m01...m36 such that each column has information about a status for that given month. Each number of the month are x months after month 0. Month 0 is the month in "lastdate" below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data testing;
    set subdata;
    %let lastdate = %sysfunc(inputn(202012,yymmn6.));
    %let monthdiff=%sysfunc(INTCK(MONTH,date1,&amp;amp;lastdate));
    %let t0=m&amp;amp;monthdiff.;
    %let t1=m%eval(&amp;amp;monthdiff-1).;
    %let t2=m%eval(&amp;amp;monthdiff-2).;
    %let t3=m%eval(&amp;amp;monthdiff-3).;
    %let t4=m%eval(&amp;amp;monthdiff-4).;
    %let t5=m%eval(&amp;amp;monthdiff-5).;
    %let t6=m%eval(&amp;amp;monthdiff-6).;
...
...
Check conditions for each t, etc.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example, if "date1" is 7 months away from the "lastdate" variable, then monthdiff will equal 7, t0=m7,t1=m6, so on and so forth. Then I will check if each tx variable (which references an mx column) has a certain value and if it does, an indicator variable will generate a 1.&lt;/P&gt;&lt;P&gt;When I try to run the %let monthdiff=%sysfunc(INTCK(MONTH,date1,&amp;amp;lastdate)) line, I get the ERROR: Argument 2 to function INTCK referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number and then ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated. Date1 is the column with dates that will dynamically change the monthdiff variable, and thus each "t" variable. How can I pass that date column into the INTCK function?&lt;/P&gt;&lt;P&gt;I'm very new to sas. I also realize I can easily change the "%let t1, let t2, etc." lines into a macro but I ran into other issues with that.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 18:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717967#M222110</guid>
      <dc:creator>sashelppls</dc:creator>
      <dc:date>2021-02-09T18:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717971#M222113</link>
      <description>&lt;P&gt;This statement does not make any sense in your problem&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let monthdiff=%sysfunc(INTCK(MONTH,date1,&amp;amp;lastdate));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;DATE1 is just a five character string to the macro processor.&amp;nbsp; What actual DATE are you trying to reference here?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is a macro variable DATE1 (which I don't see any place where you have defined such a macro variable) then use &amp;amp;DATE1.&lt;/P&gt;
&lt;P&gt;If it is the value of a variable in your dataset named DATE1 then use the function INTCK() directly in your data step instead and assign the value to a variable in your data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;monthdiff = intck('month',date1,&amp;amp;lastedate);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then use the resulting integer as an index into an array to find the appropriate Mxxx variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array m m1-m12 ;
want = m[monthdiff];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 18:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717971#M222113</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-09T18:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717977#M222116</link>
      <description>&lt;P&gt;%LET is not a sas data step statement but a declarative one to be coded out of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should use next code instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testing;
    set subdata;
       lastdate = input('20201201',yymmdd8.);
       monthdiff= INTCK(MONTH,date1,lastdate);
       t0='m' || monthdiff;
       t1='m' || monthdiff-1;
       t2='m' || monthdiff-2;
       t3='m' || monthdiff-3;
       t4='m' || monthdiff-4;
       t5='m' || monthdiff-5;
       t6='m' || monthdiff-6;
     ..........&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thus can be shorten by using an array and a do loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testing;
    set subdata;
       lastdate = inputn(20201201,yymmdd8.);
       monthdiff= INTCK(MONTH,date1,lastdate);
	   
	   array tx {} T0-T6;  /* or Tn where n is the last one */
	   do i=0 to dim(tx);
	      tx(i) = monthdiff - i;
	   end;
/***	   
       t0='m' || monthdiff;
       t1='m' || monthdiff-1;
       t2='m' || monthdiff-2;
       t3='m' || monthdiff-3;
       t4='m' || monthdiff-4;
       t5='m' || monthdiff-5;
       t6='m' || monthdiff-6;
***/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need the Tn macro variables for future use than the right function is CALL SYMPUT as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	   do i=0 to dim(tx);
	      tx(i) = monthdiff - i;
             call symput(vname(tx(i)) , tx(i));
	   end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 19:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717977#M222116</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-09T19:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717985#M222120</link>
      <description>&lt;P&gt;Thank you! It would actually have to be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;tx(i) = 'm'||monthdiff - i;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And since the variable names are m1,...m36, would I just do an IF THEN statement outside the do loop as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;do i=0 to dim(tx);
	      tx(i) = 'm'|| monthdiff - i;
             call symput(vname(tx(i)) , tx(i));
	   end;
if tx(1)='A' and tx(2)='G'...then PERF=1; else PERF=0;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 19:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717985#M222120</guid>
      <dc:creator>sashelppls</dc:creator>
      <dc:date>2021-02-09T19:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717997#M222124</link>
      <description>&lt;P&gt;I cannot make heads or tails of what you are actually trying to do. I cannot even figure out how macro variables even enter into the problem as you have described it so far.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post examples of the input data and explain what you are trying to do.&amp;nbsp; Post the expected output for the given input.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 20:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/717997#M222124</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-09T20:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/718000#M222125</link>
      <description>&lt;P&gt;There are columns in my dataset, each named m1, m2, etc. etc.. Each of these columns have a value I need to check. Ultimately, I'm creating a new variable after checking some of these m1,m2, etc. columns. For example, if m1='A',m2='Z',etc. the new variable PERF=1, otherwise it equals 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not checking the same m variables for every record. The variables I check are dependent on a certain date (date1) and how far away that date is (in months) from a lastdate variable. For example, if the difference between those 2 dates are 7, then I will check m7='A',m6=Z', for 6 variables (so I will check from m7 though m1). If the difference is 10 I will check m10 though m4. So it's clearly dynamic for every observation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The monthdiff variable is the variable I created that determines the difference in months between the two dates. My goal was to use this number as a reference to the first "m" column I would check (which I labeled as t0). Then, the column 'm'||monthdiff-1 would be the next column I would check. And so on and so forth. If all of these columns I checked matched the criteria I was looking for, then the new variable PERF=1, otherwise it equals 0. I've been trying to reference the other columns using the monthdiff variable, that's what the problem was. I am new to sas and just based off research, was under the impression I needed to use macros for this case.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 20:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/718000#M222125</guid>
      <dc:creator>sashelppls</dc:creator>
      <dc:date>2021-02-09T20:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/718003#M222127</link>
      <description>&lt;P&gt;So there is no need for macro code for this.&lt;/P&gt;
&lt;P&gt;You can use an array to allow you reference the value of M7 by using an index of 7 into an array of the variables named M1, M2, ....&lt;/P&gt;
&lt;P&gt;You have not said how many M variables there are. What is the name of the two date varaibles you need to compare to calculate the target index.&amp;nbsp; So here is a sketch.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
/* How many M variables are there? */
  array m m1-m20;
/* Is&amp;nbsp;this&amp;nbsp;the&amp;nbsp;right&amp;nbsp;direction?&amp;nbsp;Or&amp;nbsp;is&amp;nbsp;it&amp;nbsp;lastdate,date1&amp;nbsp;?&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;monthdiff&amp;nbsp;=&amp;nbsp;intck('month',date1,lastdate)&amp;nbsp;;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;perf&amp;nbsp;=&amp;nbsp;0;
/* MONTHDIF cannot be one or there is no way to index to monthdiff-1 */
/* MONTHDIF cannot be larger than the size of the array */
&amp;nbsp;&amp;nbsp;if&amp;nbsp;1 &amp;lt; monthdiff&amp;nbsp;&amp;lt;= dim(m)&amp;nbsp;then&amp;nbsp;if&amp;nbsp;m[monthdiff]='A'&amp;nbsp;and&amp;nbsp;m[monthdiff-1]='Z'&amp;nbsp;then&amp;nbsp;perf=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will need to make it match your dataset. Or ask more directed questions.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 20:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/718003#M222127</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-09T20:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: INTCK Invalid Value in Macro Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/718040#M222135</link>
      <description>&lt;P&gt;1) Are the 36 variables m1 - m36 new or already in your input?&lt;/P&gt;
&lt;P&gt;2) If you already know that there should be 36 variables named m1-m36&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;why do you need to create their list (created by the loop in t1-t36 variables) ?&lt;/P&gt;
&lt;P&gt;3)&amp;nbsp;&amp;nbsp;It seems that you don't need the macro variables at all.&lt;/P&gt;
&lt;P&gt;4) You calculate the month difference which is an integer probably has the&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;value 0 to 36 if I guess correctly.&lt;/P&gt;
&lt;P&gt;5) The logic of &lt;STRONG&gt;which variables to check&lt;/STRONG&gt; (m1-m36) and &lt;STRONG&gt;what values&lt;/STRONG&gt; should&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; each&amp;nbsp;of them be compared to, is absolutely not clear.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;tx(1) = 'm1' cannot be equal to 'A' !!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 21:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INTCK-Invalid-Value-in-Macro-Function/m-p/718040#M222135</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-09T21:55:23Z</dc:date>
    </item>
  </channel>
</rss>

