<?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: PROC SQL: :INTO different macro variables based on where logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-INTO-different-macro-variables-based-on-where-logic/m-p/581337#M165221</link>
    <description>&lt;P&gt;A macro variable defined within a macro gets per default a scope of local. You need to use a %global statement to also use this macro variable outside of the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  array createVars {*} dog_breed dog_age dog_weight  vet_city vet_name;
  stop;
run;

%macro test (val);
  %global &amp;amp;val._list;
  proc sql;
    select name into :&amp;amp;val._list separated by " " 
     from dictionary.columns where libname = "WORK" and memname = "TEST" and 
     upcase(name) contains "%upcase(&amp;amp;val.)";
  quit;
%mend;

%test(dog);
%put &amp;amp;dog_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You also need to upcase the names for the where clause to filter the data case insensitive.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2019 03:19:00 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-08-15T03:19:00Z</dc:date>
    <item>
      <title>PROC SQL: :INTO different macro variables based on where logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-INTO-different-macro-variables-based-on-where-logic/m-p/581336#M165220</link>
      <description>&lt;P&gt;My goal is to create 20 lists containing the names that have a specified value in their name, e.g.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;dog_list&lt;/EM&gt; for field names named, e.g.,&amp;nbsp; dog_breed dog_age dog_weight&lt;/P&gt;&lt;P&gt;&lt;EM&gt;vet_list&lt;/EM&gt; for field names named, e.g., vet_city vet_name&lt;/P&gt;&lt;P&gt;and so on..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tried this:&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 test (val) ;

proc sql ;
select name into :&amp;amp;val._list separated by " " 
from dictionary.columns where libname = "WORK" and memname = "TEST" and 
name contains "&amp;amp;val." ;
quit ;

%mend ; 

%test(dog) ;

%put &amp;amp;dog_list ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I got the warning: "Apparent symbolic reference DOG_LIST not resolved."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the issue here that &amp;amp;val._list resolves after the into statement creates &amp;amp;val._list as a macro variable? I'm really not sure how to resolve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could just write this out in 20 select statements, but I feel like there's some big concept I'm missing.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 02:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-INTO-different-macro-variables-based-on-where-logic/m-p/581336#M165220</guid>
      <dc:creator>SAStronomical</dc:creator>
      <dc:date>2019-08-15T02:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: :INTO different macro variables based on where logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-INTO-different-macro-variables-based-on-where-logic/m-p/581337#M165221</link>
      <description>&lt;P&gt;A macro variable defined within a macro gets per default a scope of local. You need to use a %global statement to also use this macro variable outside of the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  array createVars {*} dog_breed dog_age dog_weight  vet_city vet_name;
  stop;
run;

%macro test (val);
  %global &amp;amp;val._list;
  proc sql;
    select name into :&amp;amp;val._list separated by " " 
     from dictionary.columns where libname = "WORK" and memname = "TEST" and 
     upcase(name) contains "%upcase(&amp;amp;val.)";
  quit;
%mend;

%test(dog);
%put &amp;amp;dog_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You also need to upcase the names for the where clause to filter the data case insensitive.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 03:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-INTO-different-macro-variables-based-on-where-logic/m-p/581337#M165221</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-08-15T03:19:00Z</dc:date>
    </item>
  </channel>
</rss>

