<?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: Help to define macro (Please) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769994#M244219</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code that works (without macro functions):&lt;/P&gt;&lt;PRE&gt;rsubmit;
options mprint symbolgen mlogic;
%macro Controllo_Mesi(Colonna_data,DATA_RIF,Tab_controllo);
proc sql;
create table Tabella_sintesi as 
select distinct scan("&amp;amp;Tab_controllo",2, '.') as Nome_Tabella,
          "&amp;amp;DATA_RIF" as Data_Riferimento,
            "&amp;amp;sysdate9" as Data_Controllo,
case when (substr(put(&amp;amp;Colonna_data,date9.),3,7))="&amp;amp;DATA_RIF" then 'si' else 'no' end as Presenza_Mese_Controllo format=$4.,
case when calculated Presenza_Mese_Controllo='si' then 
      (select count (*) 
      from &amp;amp;Tab_controllo 
      where substr(put(&amp;amp;Colonna_data,date9.),3,7)="&amp;amp;DATA_RIF")
else 0 end as Numero_osservazioni
from &amp;amp;Tab_controllo
group by Data_Riferimento
having calculated Numero_osservazioni;
quit;
%mend Controllo_Mesi;
endrsubmit;

&lt;/PRE&gt;&lt;P&gt;This is the code with macro functions that I would apply if it si possibile:&lt;/P&gt;&lt;PRE&gt;rsubmit;
options mprint symbolgen mlogic;
%macro Controllo_Mesi(Colonna_data,DATA_RIF,Tab_controllo);
proc sql;
create table Tabella_sintesi as 
select distinct %scan("&amp;amp;Tab_controllo",2, '.') as Nome_Tabella,
          "&amp;amp;DATA_RIF" as Data_Riferimento,
            "&amp;amp;sysdate9" as Data_Controllo,
case when (%substr(put(&amp;amp;Colonna_data,date9.),3,7))="&amp;amp;DATA_RIF" then 'si' else 'no' end as Presenza_Mese_Controllo format=$4.,
case when calculated Presenza_Mese_Controllo='si' then 
      (select count (*) 
      from &amp;amp;Tab_controllo 
      where %substr(put(&amp;amp;Colonna_data,date9.),3,7)="&amp;amp;DATA_RIF")
else 0 end as Numero_osservazioni
from &amp;amp;Tab_controllo
group by Data_Riferimento
having calculated Numero_osservazioni;
quit;
%mend Controllo_Mesi;
endrsubmit;


&lt;/PRE&gt;&lt;P&gt;Thank you very much&lt;/P&gt;</description>
    <pubDate>Thu, 23 Sep 2021 17:37:13 GMT</pubDate>
    <dc:creator>Anto180788</dc:creator>
    <dc:date>2021-09-23T17:37:13Z</dc:date>
    <item>
      <title>Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769860#M244144</link>
      <description>&lt;P&gt;Good morning everyone, I m trying to create this macro.However, everytime I try to adjust the code it says 'case when error syntax' . Why???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options mprint symbolgen noquotelenmax;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; Controllo_Mesi(Colonna_data,DATA_RIF,Tab_controllo);&lt;/P&gt;&lt;P&gt;proc sql inobs=&lt;STRONG&gt;50&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;create table Tabella_sintesi as&lt;/P&gt;&lt;P&gt;select distinct %scan(&amp;amp;Tab_controllo,&lt;STRONG&gt;2&lt;/STRONG&gt;, '.') as Nome_Tabella,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;DATA_RIF as Data_Riferimento,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;sysdate9 as Data_Controllo,&lt;/P&gt;&lt;P&gt;case when %sysfunc(substr(&amp;amp;Colonna_data,&lt;STRONG&gt;3&lt;/STRONG&gt;))= &amp;amp;DATA_RIF&amp;nbsp; then si else no end as Presenza_Mese_Controllo format=$4.,&lt;/P&gt;&lt;P&gt;case when %sysfunc(substr(&amp;amp;Colonna_data,&lt;STRONG&gt;3&lt;/STRONG&gt;))= &amp;amp;DATA_RIF and calculated Presenza_Mese_Controllo= si&lt;/P&gt;&lt;P&gt;then count(*) else &lt;STRONG&gt;0&lt;/STRONG&gt; end as Numero_osservazioni&lt;/P&gt;&lt;P&gt;from &amp;amp;Tab_controllo&lt;/P&gt;&lt;P&gt;group by Data_Riferimento&lt;/P&gt;&lt;P&gt;having calculated Numero_osservazioni;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; Controllo_Mesi;&lt;/P&gt;&lt;P&gt;endrsubmit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rsubmit;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;Controllo_Mesi&lt;/EM&gt;&lt;/STRONG&gt;(DT_OPE,JAN2021,Lgd17db.MOV_2020CONT)&lt;/P&gt;&lt;P&gt;endrsubmit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Remote submit to MYHOST commencing.&lt;/P&gt;&lt;P&gt;718&amp;nbsp; %Controllo_Mesi(DT_OPE,JAN2021,Lgd17db.MOV_2020CONT)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MPRINT(CONTROLLO_MESI):&amp;nbsp;&amp;nbsp; proc sql inobs=50;&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable TAB_CONTROLLO resolves to Lgd17db.MOV_2020CONT&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATA_RIF resolves to JAN2021&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable SYSDATE9 resolves to 23SEP2021&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "SYSDATE9".&lt;/P&gt;&lt;P&gt;718&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;23SEP2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable COLONNA_DATA resolves to DT_OPE&lt;/P&gt;&lt;P&gt;NOTE 137-205: Line generated by the invoked macro "CONTROLLO_MESI".&lt;/P&gt;&lt;P&gt;718&amp;nbsp;&amp;nbsp; proc sql inobs=50; create table Tabella_sintesi as select distinct %scan(&amp;amp;Tab_controllo,2,&lt;/P&gt;&lt;P&gt;718! '.') as Nome_Tabella,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;DATA_RIF as Data_Riferimento,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;sysdate9 as&lt;/P&gt;&lt;P&gt;718! Data_Controllo, case when %sysfunc(substr(&amp;amp;Colonna_data,3))= &amp;amp;DATA_RIF&amp;nbsp; then si&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, AS, CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, ',', '.', ANSIMISS, AS,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CROSS, EXCEPT, FULL, GROUP, HAVING, INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER, OUTER, RIGHT, UNION, WHERE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATA_RIF resolves to JAN2021&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "CONTROLLO_MESI".&lt;/P&gt;&lt;P&gt;718&amp;nbsp;&amp;nbsp; proc sql inobs=50; create table Tabella_sintesi as select distinct %scan(&amp;amp;Tab_controllo,2,&lt;/P&gt;&lt;P&gt;718! '.') as Nome_Tabella,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;DATA_RIF as Data_Riferimento,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;sysdate9 as&lt;/P&gt;&lt;P&gt;718! Data_Controllo, case when %sysfunc(substr(&amp;amp;Colonna_data,3))= &amp;amp;DATA_RIF&amp;nbsp; then si&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 76&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable COLONNA_DATA resolves to DT_OPE&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATA_RIF resolves to JAN2021&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable TAB_CONTROLLO resolves to Lgd17db.MOV_2020CONT&lt;/P&gt;&lt;P&gt;MPRINT(CONTROLLO_MESI):&amp;nbsp;&amp;nbsp; create table Tabella_sintesi as select distinct MOV_2020CONT as&lt;/P&gt;&lt;P&gt;Nome_Tabella, JAN2021 as Data_Riferimento, 23SEP2021 as Data_Controllo , case when _OPE= JAN2021&lt;/P&gt;&lt;P&gt;then si else no end as Presenza_Mese_Controllo format=$4., case when _OPE= JAN2021 and calculated&lt;/P&gt;&lt;P&gt;Presenza_Mese_Controllo= si then count(*) else 0 end as Numero_osservazioni from&lt;/P&gt;&lt;P&gt;Lgd17db.MOV_2020CONT group by Data_Riferimento having calculated Numero_osservazioni;&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 10:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769860#M244144</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-23T10:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769867#M244148</link>
      <description>&lt;P&gt;Run this command and then run the macro again&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, show us the log. Please preserve the formatting of the log by copying the log as text, then clicking on the &amp;lt;/&amp;gt; icon here in the SAS Communities and pasting the log into the Window that appears. &lt;STRONG&gt;DO NOT SKIP THIS STEP.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 11:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769867#M244148</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-23T11:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769869#M244150</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I see a few potential problems.&amp;nbsp; I would suggest trying to write the SQL step without any macro code, and get it working, then go back to generating that code via macro.&amp;nbsp; It's easier to debug SQL code on its own first, and then debug macro code after you know the SQL code works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without knowing your data, it's hard to know what will work for the CASE statements, but I would try something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when OPE= "JAN2021"&amp;nbsp; then "si" else "no" end as Presenza_Mese_Controllo format=$4.,

case when OPE= "JAN2021"&amp;nbsp; and calculated Presenza_Mese_Controllo= "si" then count(*) else&amp;nbsp;0&amp;nbsp;end as Numero_osservazioni&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, the first error looks like it's from &amp;amp;sysdate resolving to a string that is not in quotes, you could change it to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"&amp;amp;sysdate9" as Data_Controllo,  /*character variable*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or:&lt;/P&gt;
&lt;PRE&gt;"&amp;amp;sysdate9"d as Data_Controllo,   /*numeric date variable*/&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 11:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769869#M244150</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-09-23T11:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769872#M244153</link>
      <description>&lt;PRE&gt;NOTE: Remote submit to MYHOST commencing.
905  %Controllo_Mesi(DT_OPE,JAN2021,Lgd17db.MOV_2020CONT)
MLOGIC(CONTROLLO_MESI):  Beginning execution.
MLOGIC(CONTROLLO_MESI):  Parameter COLONNA_DATA has value DT_OPE
MLOGIC(CONTROLLO_MESI):  Parameter DATA_RIF has value JAN2021
MLOGIC(CONTROLLO_MESI):  Parameter TAB_CONTROLLO has value Lgd17db.MOV_2020CONT


MPRINT(CONTROLLO_MESI):   proc sql inobs=50;
SYMBOLGEN:  Macro variable TAB_CONTROLLO resolves to Lgd17db.MOV_2020CONT
SYMBOLGEN:  Macro variable DATA_RIF resolves to JAN2021
SYMBOLGEN:  Macro variable SYSDATE9 resolves to 23SEP2021
NOTE: Line generated by the macro variable "SYSDATE9".
905           23SEP2021
                -------
                22
SYMBOLGEN:  Macro variable COLONNA_DATA resolves to DT_OPE
NOTE 137-205: Line generated by the invoked macro "CONTROLLO_MESI".
905   proc sql inobs=50; create table Tabella_sintesi as select distinct %scan(&amp;amp;Tab_controllo,2,
905! '.') as Nome_Tabella,         &amp;amp;DATA_RIF as Data_Riferimento,         &amp;amp;sysdate9 as
905! Data_Controllo, case when %substr(&amp;amp;Colonna_data,3)= &amp;amp;DATA_RIF then si else no end
                          ----
                          22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=,
              &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, AS, CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE,
              LT, LTT, NE, NET, OR, ^=, |, ||, ~=.

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, ',', '.', ANSIMISS, AS,
              CROSS, EXCEPT, FULL, GROUP, HAVING, INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS,
              ORDER, OUTER, RIGHT, UNION, WHERE.

SYMBOLGEN:  Macro variable DATA_RIF resolves to JAN2021
NOTE: Line generated by the invoked macro "CONTROLLO_MESI".
905   proc sql inobs=50; create table Tabella_sintesi as select distinct %scan(&amp;amp;Tab_controllo,2,
905! '.') as Nome_Tabella,         &amp;amp;DATA_RIF as Data_Riferimento,         &amp;amp;sysdate9 as
905! Data_Controllo, case when %substr(&amp;amp;Colonna_data,3)= &amp;amp;DATA_RIF then si else no end
                          ----
                          76
ERROR 76-322: Syntax error, statement will be ignored.

SYMBOLGEN:  Macro variable COLONNA_DATA resolves to DT_OPE
SYMBOLGEN:  Macro variable DATA_RIF resolves to JAN2021
SYMBOLGEN:  Macro variable TAB_CONTROLLO resolves to Lgd17db.MOV_2020CONT
MPRINT(CONTROLLO_MESI):   create table Tabella_sintesi as select distinct MOV_2020CONT as
Nome_Tabella, JAN2021 as Data_Riferimento, 23SEP2021 as Data_Controllo , case when _OPE= JAN2021
then si else no end as Presenza_Mese_Controllo format=$4., case when _OPE= JAN2021 and calculated
Presenza_Mese_Controllo= si then count(*) else 0 end as Numero_osservazioni from
Lgd17db.MOV_2020CONT group by Data_Riferimento having calculated Numero_osservazioni;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
MPRINT(CONTROLLO_MESI):   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

MLOGIC(CONTROLLO_MESI):  Ending execution.
906  endrsubmit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Sep 2021 12:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769872#M244153</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-23T12:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769875#M244156</link>
      <description>&lt;P&gt;When you use a macro variable, and then run the code, the macro variable is replaced with its value, and the result must be legal valid working SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this part of your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;sysdate9 as Data_Controllo,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;becomes&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;22SEP2021 as Data_Controllo,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this is not legal valid working SAS code. What do you need to do to fix this so that it is legal valid working SAS code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 12:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769875#M244156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-23T12:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769890#M244162</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;Thanks to reply me&lt;/P&gt;&lt;P&gt;You are right. I will give more informations for a better understanding.&lt;/P&gt;&lt;P&gt;I have to develop a macro to do a report which show if there is the reference month that are you searching in a dataset and how many observations there are.&lt;/P&gt;&lt;P&gt;First of all , i tried to develop the code with %let statements. I have 3 %let statements:&lt;/P&gt;&lt;P&gt;%let = DT_OPE ( the date variable of dataset of the test. In the dataset is a numeric variable )&lt;/P&gt;&lt;P&gt;%let= JAN2021 ( is the reference month which I have to control if it is present in dataset through DT_OPE&lt;/P&gt;&lt;P&gt;%let= lgd17db.MOV_2020CONT ( it is dataset of the test)&lt;/P&gt;&lt;P&gt;The report should have Name of table (name after the dot), Reference month, date of control ( done it with &amp;amp;sysdate9), flag of presence of reference month, number of observation of reference month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I the cade I need to convert DT_OPE in character because i need to extract the last 7 words.&lt;/P&gt;&lt;P&gt;I tried to use %substr without put ,because the calling macro is already a string. So i shouldn t need the conversation. However, using %substr it results error.&lt;/P&gt;&lt;P&gt;Now I have tried to run the macro code without some macro functons and it works.&lt;/P&gt;&lt;P&gt;I don't know why the macro code gave me error using macro functons &amp;amp;scan, %substr.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 12:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769890#M244162</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-23T12:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769891#M244163</link>
      <description>&lt;P&gt;Please show the macro code (without some macro functions) that works, and the macro code (with macro functions) that does not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try to make an example with only a small difference between the code that works, and the code that does not work.&amp;nbsp; For example, a simpler example where the only difference is one CASE statement which does not work as you hoped:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when %sysfunc(substr(&amp;amp;Colonna_data,3))= &amp;amp;DATA_RIF  then si else no end as Presenza_Mese_Controllo format=$4.,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But does work when you remove the macro code and replace it with SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 12:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769891#M244163</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-09-23T12:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769893#M244164</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;Thank you for your observations.&lt;/P&gt;&lt;P&gt;I looked that i missed to write quoting marks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 13:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769893#M244164</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-23T13:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769900#M244169</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the code that works (without no macro fucntions):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;NOTE: Remote submit to MYHOST complete.
243  rsubmit;
NOTE: Remote submit to MYHOST commencing.
1079  %Controllo_Mesi(DT_RIF,JAN2021,Lgd17db.SALDO_MENS)
MLOGIC(CONTROLLO_MESI):  Beginning execution.
MLOGIC(CONTROLLO_MESI):  Parameter COLONNA_DATA has value DT_RIF
MLOGIC(CONTROLLO_MESI):  Parameter DATA_RIF has value JAN2021
MLOGIC(CONTROLLO_MESI):  Parameter TAB_CONTROLLO has value Lgd17db.SALDO_MENS


MPRINT(CONTROLLO_MESI):   proc sql inobs=50;
SYMBOLGEN:  Macro variable TAB_CONTROLLO resolves to Lgd17db.SALDO_MENS
SYMBOLGEN:  Macro variable DATA_RIF resolves to JAN2021
SYMBOLGEN:  Macro variable SYSDATE9 resolves to 23SEP2021
SYMBOLGEN:  Macro variable COLONNA_DATA resolves to DT_RIF
SYMBOLGEN:  Macro variable DATA_RIF resolves to JAN2021
SYMBOLGEN:  Macro variable COLONNA_DATA resolves to DT_RIF
SYMBOLGEN:  Macro variable DATA_RIF resolves to JAN2021
SYMBOLGEN:  Macro variable TAB_CONTROLLO resolves to Lgd17db.SALDO_MENS
MPRINT(CONTROLLO_MESI):   create table Tabella_sintesi as select distinct
scan("Lgd17db.SALDO_MENS",2, '.') as Nome_Tabella, "JAN2021" as Data_Riferimento, "23SEP2021" as
Data_Controllo, case when substr(put(DT_RIF,date9.),3,7)= "JAN2021" then "si" else "no" end as
Presenza_Mese_Controllo format=$4., case when substr(put(DT_RIF,date9.),3,7)= "JAN2021" and
calculated Presenza_Mese_Controllo= "si" then count(*) else 0 end as Numero_osservazioni from
Lgd17db.SALDO_MENS group by Data_Riferimento having calculated Numero_osservazioni;
NOTE: At least one nonessential grouping column reference has been removed from a GROUP BY's
      reference list.
NOTE: The query requires remerging summary statistics back with the original data.
WARNING: Only 50 records were read from LGD17DB.SALDO_MENS due to INOBS= option.
NOTE: Table WORK.TABELLA_SINTESI created, with 0 rows and 5 columns.

MPRINT(CONTROLLO_MESI):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.27 seconds
      cpu time            0.02 seconds

&lt;/PRE&gt;&lt;P&gt;This is the macro code with macro functions (not work):&lt;/P&gt;&lt;PRE&gt;NOTE: Remote submit to MYHOST commencing.
1198  %Controllo_Mesi(DT_OPE,JAN2021,Lgd17db.MOV_2020CONT)
MLOGIC(CONTROLLO_MESI):  Beginning execution.
MLOGIC(CONTROLLO_MESI):  Parameter COLONNA_DATA has value DT_OPE
MLOGIC(CONTROLLO_MESI):  Parameter DATA_RIF has value JAN2021
MLOGIC(CONTROLLO_MESI):  Parameter TAB_CONTROLLO has value Lgd17db.MOV_2020CONT
SYMBOLGEN:  Macro variable TAB_CONTROLLO resolves to Lgd17db.MOV_2020CONT
SYMBOLGEN:  Macro variable COLONNA_DATA resolves to DT_OPE
ERROR: Macro function %SUBSTR has too few arguments.
NOTE: Line generated by the macro function "SUBSTR".
1198  " then count(*) else 0 end as Numero_osservazioni from Lgd17db.MOV_2020CONT group by
      -------------------------------------------------------------------------------------
      49
1198! Data_Riferimento having calculated Numero_osservazioni; quit;endrsubmit;options mprint
1198! symbolgen mlogic;proc sql inobs=50; create table Tabella_sintesi as select distinct
SYMBOLGEN:  Macro variable COLONNA_DATA resolves to DT_OPE
WARNING: Argument 3 to macro function %SUBSTR is out of range.
SYMBOLGEN:  Macro variable DATA_RIF resolves to JAN2021
NOTE: Line generated by the macro variable "DATA_RIF".
1198  " end as Presenza_Mese_Controllo format=$4., case when _OPE= JAN2021
      --------------------------------------------------------------------
      49
SYMBOLGEN:  Macro variable TAB_CONTROLLO resolves to Lgd17db.MOV_2020CONT
MPRINT(CONTROLLO_MESI):  " then count(*) else 0 end as Numero_osservazioni from
Lgd17db.MOV_2020CONT group by Data_Riferimento having calculated Numero_osservazioni;
quit;endrsubmit;options mprint symbolgen mlogic;proc sql inobs=50; create table Tabella_sintesi
as select distinct MOV_2020CONT as Nome_Tabella,         &amp;amp;DATA_RIF as Data_Riferimento,
&amp;amp;sysdate9 as Data_Controllo, case when ,3,7)= &amp;amp;DATA_RIF then "si" else "no" end as
Presenza_Mese_Controllo format=$4., case when _OPE= JAN2021 and calculated
Presenza_Mese_Controllo= "si
MLOGIC(CONTROLLO_MESI):  Ending execution.
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
             release.  Inserting white space between a quoted string and the succeeding
             identifier is recommended.

1199  endrsubmit;
NOTE: Remote submit to MYHOST complete.&lt;/PRE&gt;&lt;P&gt;in this part i m trying to apply macro functions %scan, %substr. But doesn't work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank&amp;nbsp; you very much&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 13:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769900#M244169</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-23T13:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769938#M244194</link>
      <description>&lt;P&gt;That log is helpful. Can you please show the macro code (macro definition) that works, and the macro code that does not work?&amp;nbsp; So show both macro definitions, from %macro to %mend?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My guess is you should be using substr and scan, not the macro functions %substr and %scan.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you'll want something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when substr(put(&amp;amp;Colonna_data,date9.),3,7)= "&amp;amp;DATA_RIF" then "si" else "no" end as Presenza_Mese_Controllo format=$4.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That uses the regular SUBSTR function not %SUBSTR, because you want the substring of a text string where the value comes from a data set variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But seeing both macro definitions will help confirm that guess.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're definitely getting closer. : )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 15:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769938#M244194</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-09-23T15:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769994#M244219</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code that works (without macro functions):&lt;/P&gt;&lt;PRE&gt;rsubmit;
options mprint symbolgen mlogic;
%macro Controllo_Mesi(Colonna_data,DATA_RIF,Tab_controllo);
proc sql;
create table Tabella_sintesi as 
select distinct scan("&amp;amp;Tab_controllo",2, '.') as Nome_Tabella,
          "&amp;amp;DATA_RIF" as Data_Riferimento,
            "&amp;amp;sysdate9" as Data_Controllo,
case when (substr(put(&amp;amp;Colonna_data,date9.),3,7))="&amp;amp;DATA_RIF" then 'si' else 'no' end as Presenza_Mese_Controllo format=$4.,
case when calculated Presenza_Mese_Controllo='si' then 
      (select count (*) 
      from &amp;amp;Tab_controllo 
      where substr(put(&amp;amp;Colonna_data,date9.),3,7)="&amp;amp;DATA_RIF")
else 0 end as Numero_osservazioni
from &amp;amp;Tab_controllo
group by Data_Riferimento
having calculated Numero_osservazioni;
quit;
%mend Controllo_Mesi;
endrsubmit;

&lt;/PRE&gt;&lt;P&gt;This is the code with macro functions that I would apply if it si possibile:&lt;/P&gt;&lt;PRE&gt;rsubmit;
options mprint symbolgen mlogic;
%macro Controllo_Mesi(Colonna_data,DATA_RIF,Tab_controllo);
proc sql;
create table Tabella_sintesi as 
select distinct %scan("&amp;amp;Tab_controllo",2, '.') as Nome_Tabella,
          "&amp;amp;DATA_RIF" as Data_Riferimento,
            "&amp;amp;sysdate9" as Data_Controllo,
case when (%substr(put(&amp;amp;Colonna_data,date9.),3,7))="&amp;amp;DATA_RIF" then 'si' else 'no' end as Presenza_Mese_Controllo format=$4.,
case when calculated Presenza_Mese_Controllo='si' then 
      (select count (*) 
      from &amp;amp;Tab_controllo 
      where %substr(put(&amp;amp;Colonna_data,date9.),3,7)="&amp;amp;DATA_RIF")
else 0 end as Numero_osservazioni
from &amp;amp;Tab_controllo
group by Data_Riferimento
having calculated Numero_osservazioni;
quit;
%mend Controllo_Mesi;
endrsubmit;


&lt;/PRE&gt;&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 17:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/769994#M244219</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-23T17:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770006#M244220</link>
      <description>&lt;P&gt;Why did you change the SUBSTR() function&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when (substr(put(&amp;amp;Colonna_data,date9.),3,7))="&amp;amp;DATA_RIF"
     then 'si' else 'no' 
end as Presenza_Mese_Controllo format=$4.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to %SUBSTR()?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when (%substr(put(&amp;amp;Colonna_data,date9.),3,7))="&amp;amp;DATA_RIF"
     then 'si' else 'no' 
end as Presenza_Mese_Controllo format=$4.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if we set COLLONNA_DATA to XXX the result of the %SUBSTR() function will be the string:&lt;/P&gt;
&lt;PRE&gt;t(XXX,d&lt;/PRE&gt;
&lt;P&gt;So the SAS code your macro is generating is going to be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when (t(XXX,d)="&amp;amp;DATA_RIF"
     then 'si' else 'no' 
end as Presenza_Mese_Controllo format=$4.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is just gibberish.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 18:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770006#M244220</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-23T18:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770012#M244223</link>
      <description>&lt;P&gt;Let's look at the code the macro is generating and try to decide what it is doing.&lt;/P&gt;
&lt;P&gt;Looks like you are getting a summary by the number of times the date in the variable named in parameter&amp;nbsp;Colonna_data is within the year specified in the parameter&amp;nbsp;DATA_RIF from the table named in the&amp;nbsp;Tab_controllo parameter.&amp;nbsp; Example call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Controllo_Mesi
(Colonna_data=VARNAME
,DATA_RIF=2021
,Tab_controllo=LIBNAME.TABLENAME
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You should probably simplify the logic of the SAS code before trying to convert it into a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably will want to make the variable with the SYSDATE into a numeric variable with date values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"&amp;amp;sysdate9"d as Data_Controllo format=date9.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why not just use the YEAR() function to get the year from the date variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year(&amp;amp;Colonna_data)=&amp;amp;DATA_RIF&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Perhaps you meant to supply values like MAY2021 to indicate a particular month?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(&amp;amp;colonna_data,monyy7.)&amp;nbsp;=&amp;nbsp;"&amp;amp;data_rif"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want the new variable&amp;nbsp;Data_Riferimento to be a character string?&amp;nbsp; If so then do not attach a format with a width of 4 to a character variable with a length of only 2.&amp;nbsp; There is no need to attach the $ format to character variables. If you want the variable to be long enough to store 4 bytes then set the LENGTH of the variable, not the display format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"&amp;amp;DATA_RIF" as Data_Riferimento length=4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or a number?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;DATA_RIF as Data_Riferimento &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To count how many times the date is from the year just sum the boolean expression.&amp;nbsp; You should not need to use a sub-query to re-query the same table.&amp;nbsp; That sounds very time consuming.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum(calculated Presenza_Mese_Controllo='si') as Numero_osservazioni&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also want to use -1 index in your SCAN() function to get the member name. That way users can specify WORK datasets using a one level name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;scan("&amp;amp;Tab_controllo",-1,'.') as Nome_Tabella&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 19:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770012#M244223</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-23T19:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770029#M244229</link>
      <description>&lt;P&gt;Is there anything wrong with the macro that is working?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the macro that is not working, you changed scan to %scan, and substr to %substr.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But looking at your working macro, you are using scan and substr correctly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;scan and substr work on the values of dataset variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%scan and %substr work on text, not the values of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even though your code is inside a macro definition, it's appropriate to use scan and substr when you want to use the value of a data step variable as an input to the function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, Tom makes excellent points about refactoring the macro.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 19:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770029#M244229</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-09-23T19:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770130#M244282</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for reply&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just supposed to change the fucntion when I defined the macro. So, without macro you use simpe substr() and when you make a macro you use %substr. I understood that isn't the same result. So, to have the expected result, i can use only the simple substr().&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 07:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770130#M244282</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-24T07:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770131#M244283</link>
      <description>&lt;P&gt;You only use a macro function when the function has to do its work while the code is being compiled, BEFORE it actually runs.&lt;/P&gt;
&lt;P&gt;Whenever a function needs to do its work while the &lt;EM&gt;resulting&lt;/EM&gt; code &lt;EM&gt;executes&lt;/EM&gt;, stay with the normal data step function.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 07:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770131#M244283</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-24T07:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770246#M244354</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for all your advices&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%Controllo_Mesi
(Colonna_data=VARNAME
,DATA_RIF=2021
,Tab_controllo=LIBNAME.TABLENAME
)&lt;/PRE&gt;&lt;P&gt;The logic is set in this way because the macro code should be use on many datasets which have different date variable name.&lt;/P&gt;&lt;P&gt;DATA_RIF is composed not only the year but also the month. For example, JAN2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;put(&amp;amp;colonna_data,monyy7.) = "&amp;amp;data_rif"&lt;/PRE&gt;&lt;P&gt;So, in dataset the date varialbe name is daymonthyear (example, 25JAN2021) which is a numeric type, I need to substring only month and year in order to set the macro variable only with MONTH and YEAR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;amp;DATA_RIF as Data_Riferimento &lt;/PRE&gt;&lt;P&gt;It should be good to use numeric variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;sum(calculated Presenza_Mese_Controllo='si') as Numero_osservazioni&lt;/PRE&gt;&lt;P&gt;I changed as you said and this works better (less time consuming).&lt;/P&gt;&lt;PRE&gt;scan("&amp;amp;Tab_controllo",-1,'.') as Nome_Tabella&lt;/PRE&gt;&lt;P&gt;I will change also this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much TOM&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 14:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770246#M244354</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-24T14:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770248#M244356</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much Quentin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"%scan and %substr work on text, not the values of variables."&lt;BR /&gt;Probably this is the problem, because &amp;amp;colonna_data is a numeric values. So it doesn't work&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 14:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770248#M244356</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-24T14:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770325#M244380</link>
      <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;many thanks for all your help to resolve my problem.&lt;/P&gt;&lt;P&gt;I would ask one more thing regarding the macro code which i have showed you.&lt;BR /&gt;Do you think is it possibile to call macro for more variable simultaneously?&lt;BR /&gt;For example:&lt;/P&gt;&lt;PRE&gt;%Controllo_Mesi(Colonna_data=VARNAME,DATA_RIF=2021,Tab_controllo=LIBNAME.TABLENAME)&lt;/PRE&gt;&lt;P&gt;This is normal mode and it is works.&lt;/P&gt;&lt;PRE&gt;%Controllo_Mesi(Colonna_data=VARNAME1, VARNAME2,DATA_RIF=MONTHYEAR,Tab_controllo=LIBNAME.TABLENAME1, LIBNAME.TABLENAME2)&lt;/PRE&gt;&lt;P&gt;If it isn't possible, I m thinking is better to add each new row in a existing table. So:&lt;/P&gt;&lt;P&gt;1) Run the macro: every time i get one row&lt;/P&gt;&lt;P&gt;2) Insert the new row in a existing table in order to store it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 17:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770325#M244380</guid>
      <dc:creator>Anto180788</dc:creator>
      <dc:date>2021-09-24T17:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help to define macro (Please)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770363#M244405</link>
      <description>&lt;P&gt;You cannot just stick another comma into the middle of your macro call.&amp;nbsp; That will result in more parameter values being pass in than the macro supports.&amp;nbsp; Plus then it looks like you are trying revert to passing the parameter values by position instead of by name. If you want to pass parameter values by position and by name in the same call the one's passed by position have to come first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a SPACE or some other character to separate the multiple variable names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Colonna_data=VARNAME1 VARNAME2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you have to add some logic in your macro for what to do when there are two variable names passed into the macro.&lt;/P&gt;
&lt;P&gt;The normal ways to perform the same action on multiple variables is define an array and then loop over an index into the array.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array column VARNAME1 VARNAME2;
do index=1 to dim(column);
   if column[index] ....
   ...
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So using a space as the delimiter is the best way to pass the list of variable names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array column &amp;amp;colonna_data;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Sep 2021 00:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-to-define-macro-Please/m-p/770363#M244405</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-25T00:04:12Z</dc:date>
    </item>
  </channel>
</rss>

