<?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: Macro List and Using IN in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636871#M189269</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is probably something simple.&amp;nbsp; I have a dataset that has one variable in it called AERODROME. It contains airport IDs as characters.&amp;nbsp; For example: CYYZ, EGGL, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _NULL_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; set EGTASK.AERODROME_NORTH_CDA;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; call symput('AERODROME_N',AERODROME);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in order to create a macro variable called AERODROME_N that is now a list of all the airport IDs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, it's not. It only contains the value from the last observation read from the dataset. You do not need a macro variable AT ALL(!). You use a sub-select:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table term_north as
select *
from ibs_comb.enroute_append
where
  depart in (select aerodrome from aerodrome_north_cda) or
  dest in (select aerodrome from aerodrome_north_cda)
order by flightdate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Apr 2020 13:47:10 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-04-02T13:47:10Z</dc:date>
    <item>
      <title>Macro List and Using IN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636868#M189268</link>
      <description>&lt;P&gt;This is probably something simple.&amp;nbsp; I have a dataset that has one variable in it called AERODROME. It contains airport IDs as characters.&amp;nbsp; For example: CYYZ, EGGL, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _NULL_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; set EGTASK.AERODROME_NORTH_CDA;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; call symput('AERODROME_N',AERODROME);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in order to create a macro variable called AERODROME_N that is now a list of all the airport IDs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then am trying the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;PROC SQL;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;CREATE TABLE EGTASK.TERM_NORTH AS &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT *&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM IBS_COMB.ENROUTE_APPEND t1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHERE depart IN ("&amp;amp;AERODROME_N") or dest IN ("&amp;amp;AERODROME_N")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ORDER BY flightdate;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;QUIT;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am just trying to get all records from IBS_COMB_ENROUTE that have a departure or destination in the macro list. What I get back is an empty dataset which I should not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight?&amp;nbsp; Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 13:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636868#M189268</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2020-04-02T13:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro List and Using IN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636871#M189269</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is probably something simple.&amp;nbsp; I have a dataset that has one variable in it called AERODROME. It contains airport IDs as characters.&amp;nbsp; For example: CYYZ, EGGL, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _NULL_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; set EGTASK.AERODROME_NORTH_CDA;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; call symput('AERODROME_N',AERODROME);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in order to create a macro variable called AERODROME_N that is now a list of all the airport IDs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, it's not. It only contains the value from the last observation read from the dataset. You do not need a macro variable AT ALL(!). You use a sub-select:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table term_north as
select *
from ibs_comb.enroute_append
where
  depart in (select aerodrome from aerodrome_north_cda) or
  dest in (select aerodrome from aerodrome_north_cda)
order by flightdate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Apr 2020 13:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636871#M189269</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-02T13:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro List and Using IN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636872#M189270</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is probably something simple.&amp;nbsp; I have a dataset that has one variable in it called AERODROME. It contains airport IDs as characters.&amp;nbsp; For example: CYYZ, EGGL, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _NULL_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; set EGTASK.AERODROME_NORTH_CDA;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; call symput('AERODROME_N',AERODROME);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in order to create a macro variable called AERODROME_N that is now a list of all the airport IDs.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think &amp;amp;AERODROME_N contains the list of all the airport IDs. It contains the ID of the very last observation in EGTASK.AERODROME_NORTH_CDA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To modify your code (and extra benefit, no macro variables needed), this seems like it would work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE EGTASK.TERM_NORTH AS
        SELECT *
        FROM IBS_COMB.ENROUTE_APPEND t1
        WHERE depart IN (select distinct aerodrome from egtask.aerodrome_north_cda)
        or dest IN (select distinct aerodrome from egtask.aerodrome_north_cda)
        ORDER BY flightdate;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Apr 2020 13:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636872#M189270</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-02T13:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro List and Using IN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636873#M189271</link>
      <description>&lt;P&gt;Probably the fastest method is a data step with a hash:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data term_north;
set ibs_comb.enroute_append;
if _n_ = 1
then do;
  declare hash h (dataset:"aerodrome_north_cda");
  h.definekey("aerodrome");
  h.definedone();
end;
if h.find(key:depart) = 0 or h.find(key:dest) = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Apr 2020 13:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636873#M189271</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-02T13:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro List and Using IN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636877#M189274</link>
      <description>&lt;P&gt;Why create the macro variable at all?&lt;BR /&gt;Does your dataset (EGTASK.AERODROME_NORTH_CDA) only have one observation?&amp;nbsp; If not then only the value from the last observation will be in your macro variable.&lt;/P&gt;
&lt;P&gt;Your later code will only work as written if the macro variable is either just one value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CYYZ&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if there is more than one value it needs to have quotes in the middle, but not at the end&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CYYZ" "EGGL&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So that when you code adds the quotes on the outside you get something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"CYYZ" "EGGL"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: SAS doesn't care whether you use spaces or commas between the values in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do want to put the list of values into a macro variable it is easier to use PROC SQL. You should just put the quotes in when you make the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select quote(trim(AERODROME))
    into :AERODROME_N separated by ' '
    from EGTASK.AERODROME_NORTH_CDA
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Apr 2020 13:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636877#M189274</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-02T13:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro List and Using IN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636889#M189277</link>
      <description>&lt;P&gt;In addition to the comments of others about the need and content, even if your macro variable did contain a list it would have been used incorrectly in the sql.&lt;/P&gt;
&lt;P&gt;Consider the case of &lt;FONT face="courier new,courier"&gt;AERODROME_N&lt;/FONT&gt; actually equaling the string value of CYYZ EGGL such as might be done with&lt;/P&gt;
&lt;P&gt;%let &lt;FONT face="courier new,courier"&gt;AERODROME_N&lt;/FONT&gt;=CYYZ EGGL;&lt;/P&gt;
&lt;P&gt;(Hint: this is one way to test your code without the faulty macro variable)&lt;/P&gt;
&lt;P&gt;Then the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
CREATE TABLE EGTASK.TERM_NORTH AS
        SELECT *
        FROM IBS_COMB.ENROUTE_APPEND t1
        WHERE depart IN ("&amp;amp;AERODROME_N") or dest IN ("&amp;amp;AERODROME_N")
        ORDER BY flightdate;
QUIT;&lt;/PRE&gt;
&lt;P&gt;Would resolve to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
CREATE TABLE EGTASK.TERM_NORTH AS
        SELECT *
        FROM IBS_COMB.ENROUTE_APPEND t1
        WHERE depart IN ("CYYZ EGGL") or dest IN ("CYYZ EGGL")
        ORDER BY flightdate;
QUIT;&lt;/PRE&gt;
&lt;P&gt;Which would be logically incorrect as there is only a single value to find that would have "all" the airports.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The IN to work as intended would have to look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        WHERE depart IN ("CYYZ" "EGGL") or dest IN ("CYYZ" "EGGL")
&lt;/PRE&gt;
&lt;P&gt;to find individual airports.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach IF my following assumptions hold:&lt;/P&gt;
&lt;P&gt;1) the data set &lt;FONT face="courier new,courier"&gt;EGTASK.AERODROME_NORTH_CDA&lt;/FONT&gt; contains some sort of regional group of locations , i.e. North&lt;/P&gt;
&lt;P&gt;2) you have a number of different groups that you use frequently&lt;/P&gt;
&lt;P&gt;3) the memberships of the groups changes infrequently&lt;/P&gt;
&lt;P&gt;4) (and very important) no location is in more than one list.&lt;/P&gt;
&lt;P&gt;If so then I might be tempted to make a format that has something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $areoregion
'CYYZ', 'EGGL' = 'North'
'BDDR', 'CCCP' = 'South'
'SCCA', 'FIDE' = 'Central'
;
run;&lt;/PRE&gt;
&lt;P&gt;And the SQL could be modified to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
CREATE TABLE EGTASK.TERM_NORTH AS
        SELECT *
        FROM IBS_COMB.ENROUTE_APPEND t1
        WHERE put(depart,$areoregion)='North' or put(dest,$areoregion.) = 'North')
        ORDER BY flightdate;
QUIT;&lt;/PRE&gt;
&lt;P&gt;This may also gain some flexibility that may be needed that would require much more coding with extra sub-queries. Consider the following:&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
CREATE TABLE EGTASK.TERM_NORTH AS
        SELECT *
        FROM IBS_COMB.ENROUTE_APPEND t1
        WHERE put(depart,$areoregion)='North' AND put(dest,$areoregion.) = 'South')
        ORDER BY flightdate;
QUIT;&lt;/PRE&gt;
&lt;P&gt;This would identify records for departure from one region and destination in another specific region.&lt;/P&gt;
&lt;P&gt;Or using&amp;nbsp; IN operator such as&lt;/P&gt;
&lt;PRE&gt;        WHERE put(depart,$areoregion) in ('North' 'Central') AND put(dest,$areoregion.) = 'South')
&lt;/PRE&gt;
&lt;P&gt;depart from multiple regions and destination in one region .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS the icon &amp;lt;/&amp;gt; or "running man" creates code boxes to keep the forum from reformatting code and Log entries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 15:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-List-and-Using-IN/m-p/636889#M189277</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-02T15:03:41Z</dc:date>
    </item>
  </channel>
</rss>

