<?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: Import csv files from a directory - based on date range in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620695#M77187</link>
    <description>&lt;P&gt;1. grab the date from the variable value&lt;/P&gt;
&lt;P&gt;2. filter that based on 15 days using an IF statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't provide example code because I'm not sure what your input looks like, there was no sample data provided that I noticed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of using wildcards to read in all text files at once. You can use FILEVAR instead to pass your filename variable and import just those files. The documentation on the INFILE statement has some examples.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;1. How would I filter.&amp;nbsp; Can I get a code example.&amp;nbsp; Would it be done here&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mps1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;infile&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;"cd &amp;amp;mydir ; ls *.csv"&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;pipe&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; filename &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;$256.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The fields are exactly the same just the data is different based on the date.&amp;nbsp; Essentially it needs to be stacked.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 22:30:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-01-28T22:30:16Z</dc:date>
    <item>
      <title>Import csv files from a directory - based on date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620673#M77181</link>
      <description>&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data _null_&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'rpt_date'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,put(today(),&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;YYMMDDn8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mydir=/myshare/myfolder/Suspense_Detail;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mps1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"cd &amp;amp;mydir ; ls *.csv"&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;pipe&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; filename &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$256.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=mps1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; filename;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; datasets;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; fileno+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mps1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; memname &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$32.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; memname = cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'csv'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,fileno);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; execute(catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; ,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'proc import datafile='&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; ,quote(catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'/'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'&amp;amp;mydir'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,filename))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; ,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'out='&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,memname,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'replace'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; ,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'dbms=csv'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; ,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;';run;'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;));&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I successfully imported about 300 separate files into sas.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;In the actual myfolder directory the naming convention is&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;sm_work_list&lt;/FONT&gt;&amp;amp;rpt_date..csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results are&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;sm_work_list_20200129.csv&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;sm_work_list_20200128.csv &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;sm_work_list_20200127.csv etc.&amp;nbsp; There are 300 in all&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I use a data null to capture the various dates as you can see above&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Questions&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1. Is there a way I can limit the pull to just the last 30 days based on the data_null I want to just pull the last 30 days worth or based on the number of days in the month.&amp;nbsp; So lets say today is 1/15/20 I would need just 15 days worth of csv files.&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;2. I would then want to combine them into one dataset.&amp;nbsp; Currently they result in separate datasets numbered.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 21:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620673#M77181</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-01-28T21:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv files from a directory - based on date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620684#M77184</link>
      <description>&lt;P&gt;1. Filter your mps1 data set. You can use the data step itself to apply the filter. The import only runs for files in that list.&lt;/P&gt;
&lt;P&gt;2. How are they to be combined? Are all the files the same so you're stacking them or do they need to be merged somehow?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the files are all the same format and need to be stacked, you're better off reading the files within a single data step that can read all the files together at once based off your filtered mps1 dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 22:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620684#M77184</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-28T22:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv files from a directory - based on date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620691#M77186</link>
      <description>&lt;P&gt;1. How would I filter.&amp;nbsp; Can I get a code example.&amp;nbsp; Would it be done here&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mps1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"cd &amp;amp;mydir ; ls *.csv"&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;pipe&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; filename &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$256.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The fields are exactly the same just the data is different based on the date.&amp;nbsp; Essentially it needs to be stacked.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 22:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620691#M77186</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-01-28T22:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv files from a directory - based on date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620695#M77187</link>
      <description>&lt;P&gt;1. grab the date from the variable value&lt;/P&gt;
&lt;P&gt;2. filter that based on 15 days using an IF statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't provide example code because I'm not sure what your input looks like, there was no sample data provided that I noticed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of using wildcards to read in all text files at once. You can use FILEVAR instead to pass your filename variable and import just those files. The documentation on the INFILE statement has some examples.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;1. How would I filter.&amp;nbsp; Can I get a code example.&amp;nbsp; Would it be done here&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mps1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;infile&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#800080"&gt;"cd &amp;amp;mydir ; ls *.csv"&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;pipe&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; filename &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;$256.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The fields are exactly the same just the data is different based on the date.&amp;nbsp; Essentially it needs to be stacked.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 22:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-csv-files-from-a-directory-based-on-date-range/m-p/620695#M77187</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-28T22:30:16Z</dc:date>
    </item>
  </channel>
</rss>

