<?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 Filtering using DATA STEP from another table in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827607#M41224</link>
    <description>&lt;P&gt;Hello, i need to do a DATA STEP filtering data from another table.&lt;/P&gt;&lt;P&gt;This example table contains the variables that I use for the filter:&lt;/P&gt;&lt;P&gt;DATA WORK.TEAMS;&lt;BR /&gt;SET SASHELP.BASEBALL (KEEP=TEAM WHERE=(TEAM IN ('Cleveland', 'Atlanta', 'Boston')));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm currently using select sql, however, it doesn't perform well. I want to use data step for this.&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.LIST_SQL AS&lt;BR /&gt;SELECT&lt;BR /&gt;t1.Name,&lt;BR /&gt;t1.Team,&lt;BR /&gt;t1.League,&lt;BR /&gt;t1.Division,&lt;BR /&gt;t1.Position&lt;BR /&gt;FROM SASHELP.BASEBALL T1&lt;BR /&gt;INNER JOIN WORK.TEAMS T2 ON T1.TEAM = T2.TEAM&lt;BR /&gt;;QUIT;&lt;/P&gt;&lt;P&gt;I can't use a variable like this below because the values i have ​​are dynamic&lt;/P&gt;&lt;P&gt;%LET TEAM = 'Cleveland', 'Atlanta', 'Boston';&lt;/P&gt;&lt;P&gt;DATA WORK.LIST_SAS;&lt;BR /&gt;SET SASHELP.BASEBALL&lt;BR /&gt;(WHERE=(TEAM IN (&amp;amp;TEAM.)));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For context, I want to filter financial transactions from codes, however, these codes vary from month to month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can transform the data of this table (TEAMS) into a variable? what is the best alternative?&lt;/P&gt;</description>
    <pubDate>Mon, 08 Aug 2022 13:44:49 GMT</pubDate>
    <dc:creator>gabrielstraliot</dc:creator>
    <dc:date>2022-08-08T13:44:49Z</dc:date>
    <item>
      <title>Filtering using DATA STEP from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827607#M41224</link>
      <description>&lt;P&gt;Hello, i need to do a DATA STEP filtering data from another table.&lt;/P&gt;&lt;P&gt;This example table contains the variables that I use for the filter:&lt;/P&gt;&lt;P&gt;DATA WORK.TEAMS;&lt;BR /&gt;SET SASHELP.BASEBALL (KEEP=TEAM WHERE=(TEAM IN ('Cleveland', 'Atlanta', 'Boston')));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm currently using select sql, however, it doesn't perform well. I want to use data step for this.&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.LIST_SQL AS&lt;BR /&gt;SELECT&lt;BR /&gt;t1.Name,&lt;BR /&gt;t1.Team,&lt;BR /&gt;t1.League,&lt;BR /&gt;t1.Division,&lt;BR /&gt;t1.Position&lt;BR /&gt;FROM SASHELP.BASEBALL T1&lt;BR /&gt;INNER JOIN WORK.TEAMS T2 ON T1.TEAM = T2.TEAM&lt;BR /&gt;;QUIT;&lt;/P&gt;&lt;P&gt;I can't use a variable like this below because the values i have ​​are dynamic&lt;/P&gt;&lt;P&gt;%LET TEAM = 'Cleveland', 'Atlanta', 'Boston';&lt;/P&gt;&lt;P&gt;DATA WORK.LIST_SAS;&lt;BR /&gt;SET SASHELP.BASEBALL&lt;BR /&gt;(WHERE=(TEAM IN (&amp;amp;TEAM.)));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For context, I want to filter financial transactions from codes, however, these codes vary from month to month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can transform the data of this table (TEAMS) into a variable? what is the best alternative?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 13:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827607#M41224</guid>
      <dc:creator>gabrielstraliot</dc:creator>
      <dc:date>2022-08-08T13:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering using DATA STEP from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827623#M41227</link>
      <description>&lt;P&gt;When you say "codes vary from month to month" do you mean that the codes in the data change or the codes that you want to use change?&lt;/P&gt;
&lt;P&gt;Also from "month to month" brings up a question of are you using all the codes for a given month? (We do not have your data or your experience so we do not know if this condition holds.) If so it might be easier to specify dates than a bunch of codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think your basic join is inefficient. Filter first instead of applying a where after the join. A left join can select just the records you want a bit quicker I think. Please see:&lt;/P&gt;
&lt;PRE&gt;data teamfilter;
   input team $14.;
datalines;
Cleveland
Atlanta
Boston
;

PROC SQL;
   CREATE TABLE WORK.LIST_SQL AS
   SELECT
   t1.Name,
   t1.Team,
   t1.League,
   t1.Division,
   t1.Position
   FROM work.teamfilter as a
        left join
        SASHELP.BASEBALL T1
       on T1.TEAM = A.TEAM
;QUIT;&lt;/PRE&gt;
&lt;P&gt;How many codes are you looking at? It may be easier to place a list in a data set as shown than to write some sort of moderately ugly macro code to substitute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By dynamic do you mean this list is generated elsewhere in data or code? If so, show us how that goes because replacing a macro variable with a list is about the only other simple approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 14:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827623#M41227</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-08T14:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering using DATA STEP from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827654#M41230</link>
      <description>&lt;P&gt;I simulated the data to better exemplify:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA WORK.Transactions;&lt;/P&gt;&lt;P&gt;INFILE DATALINES dlm = ",";&lt;BR /&gt;INPUT ACCOUNT $ TYPE $ VALUE DATE :ddmmyy10.;&lt;BR /&gt;format DATE :ddmmyy10.;&lt;/P&gt;&lt;P&gt;DATALINES;&lt;BR /&gt;00001-1,C,20,14/06/2022&lt;BR /&gt;00002-2,D,1,20/06/2022&lt;BR /&gt;00003-3,D,28,16/05/2022&lt;BR /&gt;00001-2,D,100,04/07/2022&lt;BR /&gt;00002-3,D,50,11/07/2022&lt;BR /&gt;00003-4,C,50,27/06/2022&lt;BR /&gt;00001-3,C,30,18/07/2022&lt;BR /&gt;00001-1,D,500,09/05/2022&lt;BR /&gt;00002-2,C,10000,14/06/2022&lt;BR /&gt;00003-3,D,10000,01/08/2022&lt;BR /&gt;00001-2,C,10,16/05/2022&lt;BR /&gt;00002-3,D,12,14/06/2022&lt;BR /&gt;00003-4,C,90,06/06/2022&lt;BR /&gt;00001-3,D,2,04/07/2022&lt;BR /&gt;00001-1,D,20,14/06/2022&lt;BR /&gt;00002-2,D,1,18/07/2022&lt;BR /&gt;00003-3,C,28,14/06/2022&lt;BR /&gt;00001-2,D,100,09/05/2022&lt;BR /&gt;00002-3,C,50,11/07/2022&lt;BR /&gt;00003-4,D,50,18/07/2022&lt;BR /&gt;00001-3,C,30,02/05/2022&lt;BR /&gt;00001-1,D,500,25/07/2022&lt;BR /&gt;00002-2,C,10000,30/05/2022&lt;BR /&gt;00003-3,C,10000,25/07/2022&lt;BR /&gt;00001-2,C,10,01/08/2022&lt;BR /&gt;00002-3,D,12,14/06/2022&lt;BR /&gt;00003-4,C,90,25/07/2022&lt;BR /&gt;00001-3,D,2,30/05/2022&lt;BR /&gt;;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA WORK.ACCOUNTS;&lt;BR /&gt;INFILE DATALINES dlm = ",";&lt;/P&gt;&lt;P&gt;INPUT NAME $ ACCOUNT $ MONTH :ddmmyy10. SELECT $;&lt;BR /&gt;format MONTH MMYYS.;&lt;/P&gt;&lt;P&gt;DATALINES;&lt;BR /&gt;Jacoby Brook,00001-1,01/06/22,Y&lt;BR /&gt;Sample Billy,00002-2,01/06/22,N&lt;BR /&gt;Bando Chris,00003-3,01/06/22,N&lt;BR /&gt;Castillo Carmen,00001-2,01/06/22,Y&lt;BR /&gt;Hall Mel,00003-4,01/06/22,N&lt;BR /&gt;Barrett Marty,00002-3,01/07/22,N&lt;BR /&gt;Hall Mel,00003-4,01/07/22,Y&lt;BR /&gt;Moreno Omar,00001-3,01/07/22,Y&lt;BR /&gt;Jacoby Brook,00001-1,01/07/22,N&lt;BR /&gt;;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of how I do it. I need to separate transactions. Thanks for the LEFT JOIN suggestion. But can I do it by DATA STEP to perform better&lt;BR /&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET DATAI = %SYSFUNC(INTNX(MONTH, %SYSFUNC(TODAY()), -1, B), DATE9.);&lt;BR /&gt;%LET DATAF = %SYSFUNC(INTNX(MONTH, %SYSFUNC(TODAY()), -1, E), DATE9.);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.FINAL_LIST_SQL AS&lt;BR /&gt;SELECT t1.ACCOUNT,&lt;BR /&gt;t2.NAME,&lt;BR /&gt;t1.TYPE,&lt;BR /&gt;t1.VALUE,&lt;BR /&gt;t1.DATE&lt;BR /&gt;FROM WORK.TRANSACTIONS t1&lt;BR /&gt;LEFT JOIN WORK.ACCOUNTS T2 ON t1.ACCOUNT = t2.ACCOUNT&lt;BR /&gt;WHERE T1.DATE BETWEEN "&amp;amp;DATAI."D AND "&amp;amp;DATAF."D AND T2.SELECT = 'Y' AND T2.MONTH BETWEEN "&amp;amp;DATAI."D AND "&amp;amp;DATAF."D&lt;BR /&gt;;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 17:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827654#M41230</guid>
      <dc:creator>gabrielstraliot</dc:creator>
      <dc:date>2022-08-08T17:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering using DATA STEP from another table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827681#M41231</link>
      <description>&lt;P&gt;Filtering for values contained in another dataset is best done with a hash object.&lt;/P&gt;
&lt;P&gt;Say you have two datasets "have" and "lookup", both containing a variable "key".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if _n_ =1
then do;
  declare hash l (dataset:"lookup");
  l.definekey("key");
  l.definedone();
end;
if l.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Aug 2022 19:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-using-DATA-STEP-from-another-table/m-p/827681#M41231</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-08T19:16:22Z</dc:date>
    </item>
  </channel>
</rss>

