<?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 MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938293#M368566</link>
    <description>&lt;P&gt;Helo, i have two tables as&amp;nbsp; describe below:&lt;/P&gt;&lt;P&gt;Tab_A - one columns called source with three rows.&lt;/P&gt;&lt;P&gt;Tab B - Five columns where one of them is the same as tab A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex.&lt;/P&gt;&lt;P&gt;Tab A&amp;nbsp;&lt;/P&gt;&lt;P&gt;Source&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;C;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tab B&lt;/P&gt;&lt;P&gt;Source&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01.01.2024&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10000&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01.01.2024&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11000&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01.01.2024&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12000&lt;/P&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;I want to loop through the table A to get the records from Table B where the Tab A values are&amp;nbsp; filters&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql&lt;/P&gt;&lt;P&gt;select * from Tab B where source = 'A'&amp;nbsp;&lt;/P&gt;&lt;P&gt;then&lt;/P&gt;&lt;P&gt;select * from Tab B where source = 'B'&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then&amp;nbsp;&lt;/P&gt;&lt;P&gt;select * from Tab B where source = 'C'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use ut in a macro&lt;/P&gt;</description>
    <pubDate>Mon, 05 Aug 2024 20:07:26 GMT</pubDate>
    <dc:creator>ph10</dc:creator>
    <dc:date>2024-08-05T20:07:26Z</dc:date>
    <item>
      <title>MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938293#M368566</link>
      <description>&lt;P&gt;Helo, i have two tables as&amp;nbsp; describe below:&lt;/P&gt;&lt;P&gt;Tab_A - one columns called source with three rows.&lt;/P&gt;&lt;P&gt;Tab B - Five columns where one of them is the same as tab A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex.&lt;/P&gt;&lt;P&gt;Tab A&amp;nbsp;&lt;/P&gt;&lt;P&gt;Source&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;C;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tab B&lt;/P&gt;&lt;P&gt;Source&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01.01.2024&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10000&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01.01.2024&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11000&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01.01.2024&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12000&lt;/P&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;I want to loop through the table A to get the records from Table B where the Tab A values are&amp;nbsp; filters&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql&lt;/P&gt;&lt;P&gt;select * from Tab B where source = 'A'&amp;nbsp;&lt;/P&gt;&lt;P&gt;then&lt;/P&gt;&lt;P&gt;select * from Tab B where source = 'B'&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then&amp;nbsp;&lt;/P&gt;&lt;P&gt;select * from Tab B where source = 'C'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use ut in a macro&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 20:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938293#M368566</guid>
      <dc:creator>ph10</dc:creator>
      <dc:date>2024-08-05T20:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938296#M368567</link>
      <description>&lt;P&gt;I do not understand why you want to run three queries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just use one query?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from TabB
 where source in (select source from TabA)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to whether you need a macro or not and if so what type of macro you will need to describe what part of the code you would want to change with each different call to the macro.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 20:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938296#M368567</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-05T20:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938301#M368569</link>
      <description>&lt;P&gt;I would like to create three tables with the name of the variable coming from tabA,&lt;BR /&gt;That's the reason to try to build it by macro.&lt;BR /&gt;For example:&lt;BR /&gt;Table A_source1 will come from TabB where Source = TabA, first record&lt;/P&gt;&lt;P&gt;Table A_source2 will come from TabB where Source = TabA, second record&lt;/P&gt;&lt;P&gt;Table A_source3 will come from TabB where Source = TabA, third record&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 20:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938301#M368569</guid>
      <dc:creator>ph10</dc:creator>
      <dc:date>2024-08-05T20:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938306#M368570</link>
      <description>&lt;P&gt;If you just want to stack your records then why not just use UNION?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table A as
  select * from B where source = 'A' 
  union all
  select * from B where source = 'B'  
  union all
  select * from B where source = 'C' ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2024 22:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938306#M368570</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2024-08-05T22:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938307#M368571</link>
      <description>&lt;P&gt;Seems like a silly idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would code it as a macro that take TWO inputs.&amp;nbsp; The value of SOURCE and the NAME of the output dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro subset(source,out);
proc sql;
create table &amp;amp;out as select * from tabB where source = &amp;amp;source;
quit;
%mend subset;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then use the values from TABA to call the macro.&amp;nbsp; Unless you are positive the values of SOURCE can be used to make valid (unique) dataset names I would just number the dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set tabA ;
  by source;
  if first.source;
  dsnum +1;
  call execute(cats('%nrstr(%subset)(',quote(trim(source,"'")),',',cats('tablea_source',dsnum)));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2024 23:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938307#M368571</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-05T23:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938318#M368573</link>
      <description>It looks like good, but one little comment. There is some questions when testing, so I modified to following code:&lt;BR /&gt;call execute(cats('%nrstr(%subset)(',quote(trim(source),"'"),',',cats('tablea_source',dsnum),')'));</description>
      <pubDate>Tue, 06 Aug 2024 05:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938318#M368573</guid>
      <dc:creator>Taojin</dc:creator>
      <dc:date>2024-08-06T05:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO - USING A COLUMN FROM A TABLE AS FILTER IN A PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938327#M368576</link>
      <description>&lt;P&gt;Why do you think you need to split your data in the first place?&lt;/P&gt;
&lt;P&gt;In almost all cases, splitting the data complicates further work with it.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 08:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USING-A-COLUMN-FROM-A-TABLE-AS-FILTER-IN-A-PROC-SQL/m-p/938327#M368576</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-06T08:20:44Z</dc:date>
    </item>
  </channel>
</rss>

