<?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: Bind different files from different folders in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971890#M43440</link>
    <description>&lt;P&gt;What kind of files are theses? It is very hard to tell since the names you use do not have extensions on them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you talking about SAS datasets?&amp;nbsp; If so the filenames should be in all lowercase. Such as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;stats_q1_c3.sas7bat&lt;/PRE&gt;
&lt;P&gt;or are they other types of files?&lt;/P&gt;</description>
    <pubDate>Thu, 31 Jul 2025 22:10:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-07-31T22:10:57Z</dc:date>
    <item>
      <title>Bind different files from different folders</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971815#M43438</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have 3 folders named: Country1,&amp;nbsp;Country2,&amp;nbsp;Country3.&amp;nbsp; In each, there are files named:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stats_Q1_C1,&amp;nbsp;Stats_Q1_C2,&amp;nbsp;Stats_Q1_C3,&amp;nbsp;Stats_Q2_C1,&amp;nbsp;Stats_Q2_C2,&amp;nbsp;Stats_Q2_C3. etc until Q27.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to generate an Excel file for each Q* containing the content of C1, C2, C3 together?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The content are basically frequency tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, file_Q1 will contain the content of files&amp;nbsp;Stats_Q1_C1,&amp;nbsp;Stats_Q1_C2 and&amp;nbsp;Stats_Q1_C3 in the same sheet (so an Excel file is required) one under the other.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&amp;nbsp;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 15:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971815#M43438</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-07-31T15:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Bind different files from different folders</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971830#M43439</link>
      <description>&lt;P&gt;How about that:&lt;/P&gt;
&lt;P&gt;1) some fake data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=/path/with/data;

options dlcreatedir;
libname test "&amp;amp;path.";

libname C1 "&amp;amp;path./Country1";
libname C2 "&amp;amp;path./Country2";
libname C3 "&amp;amp;path./Country3";

%macro createFakeData();
%local i j k;
data 
  %do i = 1 %to 3;
    %do j = 1 %to 27;
      %do k = 1 %to 3; 
        C&amp;amp;i..Stats_Q&amp;amp;j._C&amp;amp;k.
      %end;
    %end;
  %end;
;
set sashelp.class;
run;
%mend createFakeData;

%createFakeData()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) generate excel:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro makeExcel(path=.,j=1);
libname e XLSX "&amp;amp;path./file_Q&amp;amp;j..xlsx";
data e.file_Q&amp;amp;j.;
  set %do i = 1 %to 3;
        C&amp;amp;i..Stats_Q&amp;amp;j._C: /* : is important to grab all */  
      %end;
  ;
run;
%mend makeExcel;

%makeExcel(path=/path/for/excel/,j=1)
%makeExcel(path=/path/for/excel/,j=5)
%makeExcel(path=/path/for/excel/,j=17)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 15:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971830#M43439</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-07-31T15:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Bind different files from different folders</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971890#M43440</link>
      <description>&lt;P&gt;What kind of files are theses? It is very hard to tell since the names you use do not have extensions on them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you talking about SAS datasets?&amp;nbsp; If so the filenames should be in all lowercase. Such as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;stats_q1_c3.sas7bat&lt;/PRE&gt;
&lt;P&gt;or are they other types of files?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 22:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971890#M43440</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-31T22:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Bind different files from different folders</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971894#M43441</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;As Tom said these files are SAS dataset or CSV/TEXT files ?&lt;/P&gt;
&lt;P&gt;We need to know the extension name of these files , so we can code something base on it .&lt;/P&gt;
&lt;P&gt;I assumed these files were CSV files and the root folder of Country1,Country2,Country3 was "c:\temp\",&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and you can use OS command too, otherwise you need to resort to the macro %dirtree written by&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; to search all these sub-folders.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas &lt;/A&gt;&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;%let root_folder= c:\temp ;  *the parent path contains Country1,Country2,Country3 ;
%let want_excel = c:\temp\want.xlsx ;  *the output excel file;




filename x pipe %sysfunc(quote(dir "&amp;amp;root_folder.\*.csv" /s /b )); 
data path;
infile x length=len truncover;
input path $varying200. len;
dsn=cats(scan(path,-2,'\'),'_',scan(path,-2,'.\'));
id=scan(path,-2,'.\');
if lowcase(path) =: "&amp;amp;root_folder.\country";
run;

data _null_;
set path;
call execute(catt('proc import datafile="',path,'" out=',dsn,' dbms=csv replace;guessingrows=max;run;'));
run;

proc sort data=path out=id;
by id;
run;
data _null_;
set id ;
by id;
if first.id then call execute(cat('data ',id,';set '));
call execute(dsn);
if last.id then call execute(catt(";run;proc export data=",id," outfile='&amp;amp;want_excel.' dbms=xlsx replace;sheet='",id,"';run;"));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Aug 2025 03:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Bind-different-files-from-different-folders/m-p/971894#M43441</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-08-01T03:08:18Z</dc:date>
    </item>
  </channel>
</rss>

