<?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: How to read and import files which sits under multiples folder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/876029#M346129</link>
    <description>&lt;P&gt;Be prepared for much heartbreak if you expect to combine any of these data sets after importing into SAS. If these XLS are supposed to have the same content you may be surprised to find that IMPORT creates variables with different type and lengths, and possibly names, as decisions as to the properties of each set are made without regards to content of other files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to investigate creating CSV files from XLS and then using a data step to read each so that the sets all have the same properties.&lt;/P&gt;</description>
    <pubDate>Tue, 16 May 2023 15:15:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-05-16T15:15:16Z</dc:date>
    <item>
      <title>How to read and import files which sits under multiples folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875958#M346107</link>
      <description>&lt;P&gt;Issues is: file sits under multiple folder.&lt;/P&gt;
&lt;P&gt;For example parent path is: &lt;STRONG&gt;'C:\users\manohar\downloads\data'&lt;/STRONG&gt; then we have multiple folder with name of date as.&lt;/P&gt;
&lt;P&gt;example 01may2023, 02may2023,03may2023, under this folder. I have files named as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each folder have 1 file for example for folder 01may2023 file name is Trans 250423.xls&lt;/P&gt;
&lt;P&gt;02may2023 file name is trans 260423.xls&lt;/P&gt;
&lt;P&gt;03may 2023 folder file name is trans 270423.xls&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can some one help me here. how to import and read this file, I have to read from 2018 onwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 10:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875958#M346107</guid>
      <dc:creator>ManoharNath</dc:creator>
      <dc:date>2023-05-16T10:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to read and import files which sits under multiples folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875991#M346119</link>
      <description>&lt;P&gt;1) what is the &lt;STRONG&gt;first&lt;/STRONG&gt; file name you have to read? and in what folder ist it?&lt;/P&gt;
&lt;P&gt;2) Do the folders represent &lt;STRONG&gt;all&lt;/STRONG&gt; possible dates since '01jan2018' in &lt;STRONG&gt;sequence&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;3) can you show a &lt;STRONG&gt;formula&lt;/STRONG&gt; to calculate the excel filename using the folder name as input argument?&lt;/P&gt;
&lt;P&gt;4) Having formula, as asked above, enables generate a SAS program to import each file separately, then to keep them as separate sas data sets or concatenate them to one big data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 13:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875991#M346119</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2023-05-16T13:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to read and import files which sits under multiples folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875992#M346120</link>
      <description>&lt;P&gt;This question is discussed in the following threads before, please check:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Convert-all-XLS-files-in-directory-to-CSV-using-SAS/td-p/875494" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Convert-all-XLS-files-in-directory-to-CSV-using-SAS/td-p/875494&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/td-p/871953" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/td-p/871953&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Here you will use Windows command/path to the main folders(which includes subfolders)/file extension (.xls) to read all files regardless the name and subfolder location of the file.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 13:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875992#M346120</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-16T13:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to read and import files which sits under multiples folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875995#M346123</link>
      <description>&lt;P&gt;First step it to get the list of files into a dataset.&amp;nbsp; Since you have multiple directories you need something that can handle that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you could use this macro:&amp;nbsp;&amp;nbsp;&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;PRE&gt;&lt;CODE class=" language-sas"&gt;%dirtree(C:\users\manohar\downloads\data,out=files)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which will create a dataset with these variables.&lt;/P&gt;
&lt;PRE&gt;Output dataset structure
--NAME-- Len  Format      Description
FILENAME $256             Name of file in directory
TYPE       $1             File or Directory? (F/D)
SIZE        8 COMMA20.    Filesize in bytes
DATE        4 YYMMDD10.   Date file last modified
TIME        4 TOD8.       Time of day file last modified
DEPTH       3             Tree depth
PATH     $256             Directory name&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So say you end up with this dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files;
  infile cards dsd ;
  input filename :$256. path :$256. ;
cards;
trans 260423.xls,C:\users\manohar\downloads\data\02may2023
trans 270423.xls,C:\users\manohar\downloads\data\03may 2023
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could then try to convert the directory name into an actual date.&lt;/P&gt;
&lt;P&gt;It also looks like the XLS filename might also have a date value in DDMMYY style, although perhaps not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xls_files;
  set files;
  if upcase(scan(filename,-1,'.')) = 'XLS' ;
  dirdate = input(scan(path,-1,'\'),date11.);
  trandate = input(scan(filename,-2,' .'),ddmmyy.);
  format dirdate trandate yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now you have this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs        filename                           path                          dirdate      trandate

 1     trans 260423.xls    C:\users\manohar\downloads\data\02may2023     2023-05-02    2023-04-26
 2     trans 270423.xls    C:\users\manohar\downloads\data\03may 2023    2023-05-03    2023-04-27
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can filter by one of those calculated DATE values to find the files that represent the date you want.&lt;/P&gt;
&lt;P&gt;And then use that list to generate the code to convert the XLS sheets into SAS datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code;
  set xls_files;
  where trandate &amp;gt;= '01JAN2018'd ;
  put 'proc import file="' path +(-1) '\' filename +(-1) '" dbms=xls'
      ' out=trans_' trandate yymmddn8. ' replace;'
      'run;'
  ;
run;
%include code / source2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;529 +proc import file="C:\users\manohar\downloads\data\02may2023\trans 260423.xls" dbms=xls out=trans_20230426 replace;
529!+                                                                                                                  run;

530 +proc import file="C:\users\manohar\downloads\data\03may 2023\trans 270423.xls" dbms=xls out=trans_20230427 replace;
530!+                                                                                                                   run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2023 13:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/875995#M346123</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-16T13:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to read and import files which sits under multiples folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/876029#M346129</link>
      <description>&lt;P&gt;Be prepared for much heartbreak if you expect to combine any of these data sets after importing into SAS. If these XLS are supposed to have the same content you may be surprised to find that IMPORT creates variables with different type and lengths, and possibly names, as decisions as to the properties of each set are made without regards to content of other files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to investigate creating CSV files from XLS and then using a data step to read each so that the sets all have the same properties.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 15:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-and-import-files-which-sits-under-multiples-folder/m-p/876029#M346129</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-16T15:15:16Z</dc:date>
    </item>
  </channel>
</rss>

