<?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: What am I doing wrong with this macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617680#M181038</link>
    <description>&lt;P&gt;Since macro processing is text only, no quotes are needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro liste_region (region=);

%if &amp;amp;region. = Abitibi-Témiscamingue
%then %do;
  %let no_comte = (1, 2, 101);
  %let out=AT;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;also note that macro variables are set with %let, and each macro variable needs a separate statement.&lt;/P&gt;
&lt;P&gt;Call the macro without quotes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%liste_region(region=Abitibi-Témiscamingue)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Jan 2020 05:24:35 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-01-16T05:24:35Z</dc:date>
    <item>
      <title>What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617664#M181034</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract a subset of a dataset based on a specific input variable called "region".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my code, but I don't know why it doesn't works.&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro liste_region (region=);

%if &amp;amp;region. = "Abitibi-Témiscamingue"	%then no_comte = "(1, 2, 101)" and out="AT";

FILENAME output "/folders/myfolders/&amp;amp;out..xlsx";



data work.membres_actifs_&amp;amp;out.;
set work.membres_actifs_circ;
where NoComteResidence in no_comte;
run;

data work.membres_anciens_&amp;amp;out.  ;
set work.membres_anciens_circ;
where NoComteResidence in no_comte;
run;

proc export data=work.membres_actifs_&amp;amp;out. 
outfile=output
dbms=xlsx replace;
sheet=membres_actifs;
run;

proc export data=work.membres_anciens_&amp;amp;out.
outfile=output
dbms=xlsx replace;
sheet=membres_anciens;
run;

%mend liste_region;

%liste_region(region="Abitibi-Témiscamingue");&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It gives me the following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         %liste_region(region="Abitibi-Témiscamingue");
 NOTE: Line generated by the invoked macro "LISTE_REGION".
 73           no_comte = "(1, 2, 101)" and out="AT"
              ________
              180
 WARNING: Apparent symbolic reference OUT not resolved.
 
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 
 WARNING: Apparent symbolic reference OUT not resolved.
 NOTE: Line generated by the invoked macro "LISTE_REGION".
 73                                                                     data work.membres_actifs_&amp;amp;out.(drop=ComteMembre Titre
                                                                                                 _
                                                                                                 22
                                                                                                 200
 73       ! DateNaissance Ehnie Langue             M90 NoComteMembre NoComteResidence NoPLQ             P90 P1AN Reg Section
 73       !     Anciennete Cat:
 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.  
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 NOTE: Line generated by the invoked macro "LISTE_REGION".
 73          cp_: ind: region_adm); set work.membres_actifs_circ; where NoComteResidence in no_comte; run;
                                                                                            ________
                                                                                            22
                                                                                            76
 ERROR: Syntax error while parsing WHERE clause.
 
 ERROR 22-322: Syntax error, expecting one of the following: (, :.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.MEMBRES_ACTIFS_ may be incomplete.  When this step was stopped there were 0 observations and 18 
          variables.
 WARNING: Data set WORK.MEMBRES_ACTIFS_ was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 
 WARNING: Apparent symbolic reference OUT not resolved.
 NOTE: Line generated by the invoked macro "LISTE_REGION".
 73                                                                                                         data
 73       ! work.membres_anciens_&amp;amp;out.  (drop=ComteMembre Titre DateNaissance Ehnie Langue M90 NoComteMembre NoComteResidence NoPLQ
                                 _
                                 22
                                 200
 73       ! P90 P1AN Reg Section Anciennete
 
 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.  
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.MEMBRES_ANCIENS_ may be incomplete.  When this step was stopped there were 0 observations and 18 
          variables.
 WARNING: Data set WORK.MEMBRES_ANCIENS_ was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 
 NOTE: Line generated by the invoked macro "LISTE_REGION".
 73          Cat: cp_: ind: region_adm); set work.membres_actifs_circ; where NoComteResidence in no_comte; run;
                                                                                                 ________
                                                                                                 22
                                                                                                 76
 ERROR: Syntax error while parsing WHERE clause.
 
 ERROR 22-322: Syntax error, expecting one of the following: (, :.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 ERROR: The value ABITIBI-TÉMISCAMINGUE is not a valid SAS member name.
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.MEMBRES_ACTIFS_ may be incomplete.  When this step was stopped there were 0 observations and 48 
          variables.
 WARNING: Data set WORK.MEMBRES_ACTIFS_ was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 
 WARNING: Apparent symbolic reference OUT not resolved.
 NOTE 137-205: Line generated by the invoked macro "LISTE_REGION".
 73          Cat: cp_: ind: region_adm); set work.membres_actifs_circ; where NoComteResidence in no_comte; run;   proc sort
 73       ! data=work.membres_actifs_&amp;amp;out. ; by ComteResidence Nom Prenom; run; proc sort data=work.membres_anciens_&amp;amp;out. ; by
                                     _
                                     22
 73       ! ComteResidence Nom Prenom;
 ERROR 22-322: Syntax error, expecting one of the following: ;, (, ASCII, BUFFNO, DANISH, DATA, DATECOPY, DETAILS, DIAG, DUPOUT, 
               EBCDIC, EQUALS, FINNISH, FORCE, IN, ISA, L, LEAVE, LIST, MESSAGE, MSG, NATIONAL, NODUP, NODUPKEY, NODUPKEYS, 
               NODUPLICATE, NODUPLICATES, NODUPREC, NODUPRECS, NODUPS, NOEQUALS, NORWEGIAN, NOTHREADS, NOUNIKEY, NOUNIKEYS, 
               NOUNIQUEKEY, NOUNIQUEKEYS, NOUNIQUEREC, NOUNIQUERECS, NOUNIREC, NOUNIRECS, OSA, OUT, OVERWRITE, PAGESIZE, PRESORTED, 
               PSIZE, REVERSE, SIZE, SORTSEQ, SORTSIZE, SORTWKNO, SWEDISH, T, TAGSORT, TECH, TECHNIQUE, TESTHSI, THREADS, UNIOUT, 
               UNIQUEOUT, WKNO, WORKNO.  
 
 NOTE: Line generated by the invoked macro "LISTE_REGION".
 73          Cat: cp_: ind: region_adm); set work.membres_actifs_circ; where NoComteResidence in no_comte; run;   proc sort
 73       ! data=work.membres_actifs_&amp;amp;out. ; by ComteResidence Nom Prenom; run; proc sort data=work.membres_anciens_&amp;amp;out. ; by
                                     _
                                     200
 73       ! ComteResidence Nom Prenom;
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 WARNING: Apparent symbolic reference OUT not resolved.
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 WARNING: Apparent symbolic reference OUT not resolved.
 22: LINE and COLUMN cannot be determined.
 NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 22-322: Syntax error, expecting one of the following: ;, (, ASCII, BUFFNO, DANISH, DATA, DATECOPY, DETAILS, DIAG, DUPOUT, 
               EBCDIC, EQUALS, FINNISH, FORCE, IN, ISA, L, LEAVE, LIST, MESSAGE, MSG, NATIONAL, NODUP, NODUPKEY, NODUPKEYS, 
               NODUPLICATE, NODUPLICATES, NODUPREC, NODUPRECS, NODUPS, NOEQUALS, NORWEGIAN, NOTHREADS, NOUNIKEY, NOUNIKEYS, 
               NOUNIQUEKEY, NOUNIQUEKEYS, NOUNIQUEREC, NOUNIQUERECS, NOUNIREC, NOUNIRECS, OSA, OUT, OVERWRITE, PAGESIZE, PRESORTED, 
               PSIZE, REVERSE, SIZE, SORTSEQ, SORTSIZE, SORTWKNO, SWEDISH, T, TAGSORT, TECH, TECHNIQUE, TESTHSI, THREADS, UNIOUT, 
               UNIQUEOUT, WKNO, WORKNO.  
 200: LINE and COLUMN cannot be determined.
 NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 200-322: The symbol is not recognized and will be ignored.
 WARNING: Apparent symbolic reference OUT not resolved.
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 
 WARNING: Apparent symbolic reference OUT not resolved.
 NOTE 137-205: Line generated by the invoked macro "LISTE_REGION".
 73          run;   proc export data=work.membres_actifs_&amp;amp;out.  outfile=output dbms=xlsx replace; sheet=membres_actifs; run;  proc
                                                         _
                                                         22
 73       ! export data=work.membres_anciens_&amp;amp;out. outfile=output dbms=xlsx replace; sheet=membres_anciens; run;
 ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATA, DBLABEL, DBMS, DEBUG, FILE, LABEL, OUTFILE, OUTTABLE, 
               REPLACE, TABLE, _DEBUG_.  
 
 NOTE: Line generated by the invoked macro "LISTE_REGION".
 73          run;   proc export data=work.membres_actifs_&amp;amp;out.  outfile=output dbms=xlsx replace; sheet=membres_actifs; run;  proc
                                                         _
                                                         200
 73       ! export data=work.membres_anciens_&amp;amp;out. outfile=output dbms=xlsx replace; sheet=membres_anciens; run;
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 NOTE: PROCEDURE EXPORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 WARNING: Apparent symbolic reference OUT not resolved.
 NOTE: The SAS System stopped processing this step because of errors.
 
 
 WARNING: Apparent symbolic reference OUT not resolved.
 22: LINE and COLUMN cannot be determined.
 NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATA, DBLABEL, DBMS, DEBUG, FILE, LABEL, OUTFILE, OUTTABLE, 
               REPLACE, TABLE, _DEBUG_.  
 200: LINE and COLUMN cannot be determined.
 NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 200-322: The symbol is not recognized and will be ignored.
 NOTE: PROCEDURE EXPORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 WARNING: Apparent symbolic reference OUT not resolved.
 NOTE: The SAS System stopped processing this step because of errors.
 74         
 75         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 04:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617664#M181034</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2020-01-16T04:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617678#M181037</link>
      <description>&lt;P&gt;The first error is because you tried to reference a macro variable name OUT, but your program never defined such a macro variable.&lt;/P&gt;
&lt;P&gt;If you want to see what code your macro is generating turn on the MPRINT option.&lt;/P&gt;
&lt;P&gt;This statement does not make any sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;region. = "Abitibi-Témiscamingue"	%then no_comte = "(1, 2, 101)" and out="AT";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the test is true then the macro is going to generate this fragment of a SAS statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;no_comte = "(1, 2, 101)" and out="AT"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It kind of looks like an assignment statement.&amp;nbsp; But it is missing the semi-colon that marks the end of a statement.&lt;/P&gt;
&lt;P&gt;It does not make any sense as an assignment since it appears to be setting NO_COMTE to result of some boolean expression.&lt;/P&gt;
&lt;P&gt;Also you are tying to run it outside of any data step or proc where such an assignment statement could possibly work.&lt;/P&gt;
&lt;P&gt;Were you intending to set some macro variables instead? Something like?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;region. = "Abitibi-Témiscamingue"	%then %do;
  %let no_comte = (1, 2, 101);
  %let out=AT;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so then you should probably add either a %LOCAL or a %GLOBAL statement to your macro definition to make it clear whether you intend those macro variable to only live as long as the macro is running or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 05:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617678#M181037</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-16T05:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617680#M181038</link>
      <description>&lt;P&gt;Since macro processing is text only, no quotes are needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro liste_region (region=);

%if &amp;amp;region. = Abitibi-Témiscamingue
%then %do;
  %let no_comte = (1, 2, 101);
  %let out=AT;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;also note that macro variables are set with %let, and each macro variable needs a separate statement.&lt;/P&gt;
&lt;P&gt;Call the macro without quotes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%liste_region(region=Abitibi-Témiscamingue)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jan 2020 05:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617680#M181038</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-16T05:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617681#M181039</link>
      <description>As stated above. And I think in your first 2 data steps you need to change no_comte to &amp;amp;no_comte. for it to work as expected in the WHERE statement. Similar as you have &amp;amp;out. And as Kurt said pay attention to the double quotes because they will be part of the macro var. So no_comte with double quotes will not work in the IN part of the WHERE statement if you want to look for values in 1, 2, 101.</description>
      <pubDate>Thu, 16 Jan 2020 05:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617681#M181039</guid>
      <dc:creator>geoskiad</dc:creator>
      <dc:date>2020-01-16T05:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617695#M181047</link>
      <description>&lt;P&gt;Thinking about it a little more, you will need some additional changes to make it run without problems:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro liste_region (region=);

%if &amp;amp;region. = Abitibi-Témiscamingue
%then %do;
  %let no_comte = NoComteResidence in (1, 2, 101);
  %let out=AT;
%end;
%else %do;
  %let no_comte=;
  %let out=non_AT;
%end;

FILENAME output "/folders/myfolders/&amp;amp;out..xlsx";

data work.membres_actifs_&amp;amp;out.;
set work.membres_actifs_circ;
where &amp;amp;no_comte.;
run;

data work.membres_anciens_&amp;amp;out.;
set work.membres_anciens_circ;
where &amp;amp;no_comte.;
run;

proc export
  data=work.membres_actifs_&amp;amp;out. 
  outfile=output
  dbms=xlsx
  replace
;
sheet=membres_actifs;
run;

proc export
  data=work.membres_anciens_&amp;amp;out.
  outfile=output
  dbms=xlsx
  replace
;
sheet=membres_anciens;
run;

%mend liste_region;

%liste_region(region=Abitibi-Témiscamingue);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as we need to make sure that the macro variables are present under all conditions, and correct filenames and where statements are created.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 06:48:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617695#M181047</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-16T06:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617755#M181080</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;[...]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Were you intending to set some macro variables instead? Something like?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;region. = "Abitibi-Témiscamingue"	%then %do;
  %let no_comte = (1, 2, 101);
  %let out=AT;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so then you should probably add either a %LOCAL or a %GLOBAL statement to your macro definition to make it clear whether you intend those macro variable to only live as long as the macro is running or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exactly. I didn't know how to "express" myself of what I'm trying to achieve in a SAS-way (my apologies for this).&lt;/P&gt;
&lt;P&gt;In fact, I want to create a macro that output some filtered (the filter is no_comte) lists based on a specific parameter (here is a region).&lt;/P&gt;
&lt;P&gt;Then, inside the macro, I want to do :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If Region = "ABC" then no_comte = (1,2,3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because I want to use it later on a data step to filter it, like :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data I_want_this;&lt;/P&gt;
&lt;P&gt;set orginal_lists;&lt;/P&gt;
&lt;P&gt;where VARIABLE_TO_FILTER in (no_comte).&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the variable_to_filter is numeric, I want the variable no_comte to be a liste in the form (1, 2, 3)... I don't know if I'm clear enough ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 14:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617755#M181080</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2020-01-16T14:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617758#M181082</link>
      <description>&lt;P&gt;You should start by creating a dataset that contains the region names and the corresponding&amp;nbsp;NoComteResidence values. Then it's just a subselect in SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup;
input region :$30. NoComteResidence;
datalines;
Abitibi-Témiscamingue 1
Abitibi-Témiscamingue 2
Abitibi-Témiscamingue 101
;

proc sql;
create table work.membres_actifs_AT
as select *
from work.membres_actifs_circ
where NoComteResidence in (
  select NoComteResidence from lookup where region = "Abitibi-Témiscamingue"
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you expand the lookup table with the short codes, you can use it in the macro to create the necessary file- and dataset names.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 14:17:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617758#M181082</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-16T14:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617762#M181084</link>
      <description>&lt;P&gt;The macro processor is just a text replacement tool. So first figure out what SAS code you need to run. Code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where VARIABLE_TO_FILTER in (no_comte);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will not work since it is comparing the dataset variable VARIABLE_TO_FILTER to the dataset variable NO_COMTE. If you did want to run that code then instead of IN operator you really should just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where VARIABLE_TO_FILTER = no_comte ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sounds like you want to run this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where VARIABLE_TO_FILTER in (1 2 101);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you could get there a number of ways.&amp;nbsp; You could set a macro variable to the list of values and replace the list with a reference to the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=1 2 101 ;
...
where VARIABLE_TO_FILTER in (&amp;amp;list.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or set the whole condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let condition=VARIABLE_TO_FILTER in (1 2 101) ;
...
where &amp;amp;condition.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What code do you want to run when the user specifies a different region?&amp;nbsp; Do you want to just eliminate the WHERE statement? Use some other condition?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 14:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617762#M181084</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-16T14:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617778#M181091</link>
      <description>&lt;P&gt;I think the first one (set a macro variable to the list of values and replace the list with a reference to the macro variable) is the one that would work the best for me.&lt;BR /&gt;&lt;BR /&gt;I tried to run the code with the modifications proposed by you :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;region. = "Abitibi-Témiscamingue" %then %do;
%let no_comte = (1, 2, 101);
%let out=AT;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;all and it gives me the following error :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &amp;amp;region. = Abitibi-Témiscamingue.
The macro LISTE_REGION will stop executing.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jan 2020 15:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617778#M181091</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2020-01-16T15:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617786#M181097</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285961"&gt;@jpprovost&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I think the first one (set a macro variable to the list of values and replace the list with a reference to the macro variable) is the one that would work the best for me.&lt;BR /&gt;&lt;BR /&gt;I tried to run the code with the modifications proposed by you :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;region. = "Abitibi-Témiscamingue" %then %do;
%let no_comte = (1, 2, 101);
%let out=AT;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;all and it gives me the following error :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &amp;amp;region. = Abitibi-Témiscamingue.
The macro LISTE_REGION will stop executing.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think I may have found the reason of the error.&lt;/P&gt;
&lt;P&gt;In the name of the region Abitibi-Témiscamingue, there's a " - " which I think SAS interpret as a minus sign.&lt;/P&gt;
&lt;P&gt;Instead, I tried to fix it with %str() in the macro and also in the parameter and it seems to work.&lt;/P&gt;
&lt;P&gt;Am I doing it right ?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 15:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/617786#M181097</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2020-01-16T15:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong with this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/618772#M181564</link>
      <description>&lt;P&gt;You can make the comparison explicitly character:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro liste_region (region=);

%if "&amp;amp;region." = "Abitibi-Témiscamingue"
%then %do;
  %let no_comte = (1, 2, 101);
  %let out=AT;
%end;
%else %do;
  %let no_comte=;
  %let out=non_AT;
%end;

%put &amp;amp;=no_comte;
%put &amp;amp;=out;

%mend;

%liste_region(region=Abitibi-Témiscamingue)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Jan 2020 06:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-with-this-macro/m-p/618772#M181564</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-21T06:32:22Z</dc:date>
    </item>
  </channel>
</rss>

