<?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: Joining multiple sas files in a folder within a loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854831#M337858</link>
    <description>&lt;P&gt;There is no looping possible in PROC SQL, unless you write a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to join this ID from table ID&amp;nbsp; with multiple sas files in a folder to create a new table showing me which tables each ID exist in?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;This can be done in a SAS data step, with the SET command (and no loop needed here).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set /* your list of data set names go here */ indsname=indsname;
    dsname = indsname;
    keep dsname id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2023 13:58:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-01-20T13:58:31Z</dc:date>
    <item>
      <title>Joining multiple sas files in a folder within a loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854830#M337857</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS file containing a unique ID-&lt;/P&gt;&lt;P&gt;I want to join this ID from table ID&amp;nbsp; with multiple sas files in a folder to create a new table showing me which tables each ID exist in?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a smart way to do this instead of writing each join in a separate SAS query?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc SQL;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create table want as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select A.*, B.*&amp;nbsp;&lt;/P&gt;&lt;P&gt;from ID a&amp;nbsp;&lt;/P&gt;&lt;P&gt;left join week_10 B&lt;/P&gt;&lt;P&gt;on A.ID = B.ID&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&amp;nbsp;&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;</description>
      <pubDate>Fri, 20 Jan 2023 13:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854830#M337857</guid>
      <dc:creator>Frank_johannes</dc:creator>
      <dc:date>2023-01-20T13:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Joining multiple sas files in a folder within a loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854831#M337858</link>
      <description>&lt;P&gt;There is no looping possible in PROC SQL, unless you write a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to join this ID from table ID&amp;nbsp; with multiple sas files in a folder to create a new table showing me which tables each ID exist in?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;This can be done in a SAS data step, with the SET command (and no loop needed here).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set /* your list of data set names go here */ indsname=indsname;
    dsname = indsname;
    keep dsname id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 13:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854831#M337858</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-20T13:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Joining multiple sas files in a folder within a loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854832#M337859</link>
      <description>&lt;P&gt;Do you want to count how many observations? Or just get an 1/0 (BOOLEAN) flag for existence or not?&lt;/P&gt;
&lt;P&gt;Do you have multiple IDs you want to check?&lt;/P&gt;
&lt;P&gt;Or do you want to check ALL of the IDs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to generate a series of boolean flags for ALL of the IDS then something like this probably the simplest.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge a(keep=id in=in1) b(keep=id in=in2) .... z(keep=id in=in26) ;
  by id;
  if first.id;
  a=in1;
  b=in2;
  ...
  z=in26;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is simple enough to generate from a list of datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=mylib._all_ out=contents noprint;
run;

data names;
  set contents;
  where upcase(name)='ID';
   by memname;
   if first.memname;
   dsnum+1;
   keep libname memname dsnum;
run;

filename code temp;
data _null_;
  file code ;
  put 'merge' ;
  do while(not eof1);
    set names end=eof1;
    put libname +(-1) '.' memname '(keep=id in=in' dsnum ')' ;
  end;
  put ';' / 'by id;' / 'if first.id;' ;
  do while(not eof1);
    set names end=eof2;
    put memname '=in' dsnum ';' ;
  end;
  put 'run;' ;
  stop;
run;
%include code /source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2023 14:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854832#M337859</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-20T14:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Joining multiple sas files in a folder within a loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854851#M337871</link>
      <description>&lt;P&gt;A basic report for which ID values are in which table:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=want;
   class dsname id;
   table id,
           dsname=' '*n=' '
           /misstext=' '
   ;
run;&lt;/PRE&gt;
&lt;P&gt;Would show row with the value of ID and column for data set name and a count of how many times the value occurs in the table as the body of the table. If you are likely to have more tables than ID values then reverse the positions of ID and Dsname in the table statement of the Proc Tabulate example.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 15:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-multiple-sas-files-in-a-folder-within-a-loop/m-p/854851#M337871</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-20T15:48:03Z</dc:date>
    </item>
  </channel>
</rss>

