<?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 csvusing macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/445358#M111584</link>
    <description>&lt;P&gt;&lt;BR /&gt;I have to read this actual file der_extract_monthly_&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;_030418_20180303235454.csv and the should generated as der_extract_monthly_patsiondate.csv date and time may vary every month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Import&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;&lt;SPAN&gt;_030418_20180303235454.csv &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;file with &amp;nbsp;Date and generate it as &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;der_extract_monthly_decisiondate.csv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let fname =der_extract_monthly_patsiondate_%sysfunc(date(030418_20180303235454).csv&lt;/P&gt;&lt;P&gt;This may change every month how to hardcode this (date(030418_20180303235454)&lt;/P&gt;&lt;P&gt;%sysfunc(date(030418_20180303235454)SourceFile1 = "der_extract_monthly_decisiondate_" &amp;amp; Convert_Date(Run_Date) &amp;amp; "*" &amp;amp; ".csv"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SourceFile1 = "der_extract_monthly_decisiondate_" &amp;amp; Convert_Date(Run_Date) &amp;amp; "*" &amp;amp; ".csv"&lt;BR /&gt;NewNameFile1 = "der_extract_monthly_decisiondate.csv"&lt;/P&gt;</description>
    <pubDate>Wed, 14 Mar 2018 00:35:48 GMT</pubDate>
    <dc:creator>SAS_PA1</dc:creator>
    <dc:date>2018-03-14T00:35:48Z</dc:date>
    <item>
      <title>Import csv using macro-based filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444312#M111214</link>
      <description>&lt;P&gt;I have to read this actual file &amp;nbsp;&amp;nbsp;der_extract_monthly_patsiondate_&lt;STRONG&gt;030418_20180303235454.&lt;/STRONG&gt;csv and the should generated as&amp;nbsp;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;pat&lt;/SPAN&gt;&lt;SPAN&gt;siondate.csv date and time may vary every month.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let fname =&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;pat&lt;/SPAN&gt;&lt;SPAN&gt;siondate&lt;/SPAN&gt;_%sysfunc(date(&lt;SPAN&gt;030418_20180303235454&lt;/SPAN&gt;).csv;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;fname;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Filename fileref &amp;nbsp;FTP "/ghms/Appeals/ Reporting/Automated/Monthly/Monthly_hmp_Activity/File /aging/Reports/&amp;amp;filename."&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;final File should be generated as &amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;pat&lt;/SPAN&gt;&lt;SPAN&gt;siondate.csv please suggest the changes. Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 15:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444312#M111214</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-14T15:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444316#M111215</link>
      <description>&lt;P&gt;It isn't quite clear what your issue is.&lt;/P&gt;
&lt;P&gt;If you are trying to build a file name statement then either we need a rule for finding the part that I think you highlighted, which I think isn't likely from your description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this supposed to be the latest date attached to the file name in that folder?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you received errors when attempting to execute&lt;/P&gt;
&lt;PRE&gt;%let fname =der_extract_monthly_patsiondate_%sysfunc(date(030418_20180303235454).csv;
&lt;/PRE&gt;
&lt;P&gt;Did you try to address those?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First you are missing a )&lt;/P&gt;
&lt;PRE&gt;%let fname =der_extract_monthly_patsiondate_%sysfunc(date(030418_20180303235454)&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;.csv;
&lt;/PRE&gt;
&lt;P&gt;But that still generates an error because the function DATE is used as Date() , no parameters, and returns the current date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should run this code to see what kind of values DATE would return to a macro variable:&lt;/P&gt;
&lt;PRE&gt;%let fname =der_extract_monthly_patsiondate_%sysfunc(date(030418_20180303235454).csv;
&lt;/PRE&gt;
&lt;P&gt;If you are looking for a files name to use&amp;nbsp; in the FILENAME statement we need a rule to generate those parts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And since the location is on an FTP site that is going to reduce the typical use of an OS command to get a listing of files in the source folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may be able to get the list of files if you know how to issue and FTP Command(or sequence) to generate a list of files at that location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also please clarify what "File should be generated as &amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;pat&lt;/SPAN&gt;&lt;SPAN&gt;siondate.csv" may mean. I would expect to use the filename to create a SAS data set since you start off with "I have to read..". So it does not sound like SAS should be generating any CSV file at all.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 00:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444316#M111215</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-10T00:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444355#M111241</link>
      <description>&lt;P&gt;At given path it generates monthly report, I need to import the report datetime may vary every month I have to automate this, file should be generatef as&amp;nbsp;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;pat&lt;/SPAN&gt;&lt;SPAN&gt;siondate.csv"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 06:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444355#M111241</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-10T06:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444794#M111406</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169801"&gt;@SAS_PA1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;At given path it generates monthly report, I need to import the report datetime may vary every month I have to automate this, file should be generatef as&amp;nbsp;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;pat&lt;/SPAN&gt;&lt;SPAN&gt;siondate.csv"&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you need to import the CSV file or to read the date and time a file was created?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CAN you provide ANY rule about the name of the file?&lt;/P&gt;
&lt;P&gt;If not then you may have to use either an operating system command to get the names of the files in your source folder and the creation date and find the last one. IF that is the file you want.&lt;/P&gt;
&lt;P&gt;You can pipe the result of your OS listing results to a SAS FILENAME&lt;/P&gt;
&lt;PRE&gt;filename  dirlist PIPE "DIR d:\data\*.csv"  ;

data junk;
   infile dirlist;
   length line $100.;
   input;
   line = _infile_;
run;&lt;/PRE&gt;
&lt;P&gt;on a windows system will create a dataset junk with the contents of a directory listing, one line of text per line of result. Options on the DIR command would change the resulting input contents. The result can be parsed to find the file with the latest creation date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you could use that to create an macro variable for use in an infile statement to read the specific csv file into SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"I have to automate this, file should be generatef as&amp;nbsp;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;pat&lt;/SPAN&gt;&lt;SPAN&gt;siondate.csv" makes no sense in terms of SAS. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 15:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444794#M111406</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-12T15:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444986#M111462</link>
      <description>&lt;P&gt;This may change every month how to hardcode this&lt;/P&gt;&lt;PRE&gt;%sysfunc(date(030418_20180303235454)&lt;/PRE&gt;&lt;P&gt;SourceFile1 = "der_extract_monthly_decisiondate_" &amp;amp; Convert_Date(Run_Date) &amp;amp; "*" &amp;amp; ".csv"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NewNameFile1 = "der_extract_monthly_decisiondate.csv"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 01:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/444986#M111462</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-13T01:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/445358#M111584</link>
      <description>&lt;P&gt;&lt;BR /&gt;I have to read this actual file der_extract_monthly_&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;_030418_20180303235454.csv and the should generated as der_extract_monthly_patsiondate.csv date and time may vary every month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Import&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;&lt;SPAN&gt;_030418_20180303235454.csv &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;file with &amp;nbsp;Date and generate it as &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;der_extract_monthly_decisiondate.csv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let fname =der_extract_monthly_patsiondate_%sysfunc(date(030418_20180303235454).csv&lt;/P&gt;&lt;P&gt;This may change every month how to hardcode this (date(030418_20180303235454)&lt;/P&gt;&lt;P&gt;%sysfunc(date(030418_20180303235454)SourceFile1 = "der_extract_monthly_decisiondate_" &amp;amp; Convert_Date(Run_Date) &amp;amp; "*" &amp;amp; ".csv"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SourceFile1 = "der_extract_monthly_decisiondate_" &amp;amp; Convert_Date(Run_Date) &amp;amp; "*" &amp;amp; ".csv"&lt;BR /&gt;NewNameFile1 = "der_extract_monthly_decisiondate.csv"&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 00:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/445358#M111584</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-14T00:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/445376#M111591</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169801"&gt;@SAS_PA1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;I have to read this actual file der_extract_monthly_&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;_030418_20180303235454.csv and the should generated as der_extract_monthly_patsiondate.csv date and time may vary every month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Import&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;&lt;SPAN&gt;_030418_20180303235454.csv &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;file with &amp;nbsp;Date and generate it as &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;der_extract_monthly_decisiondate.csv&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let fname =der_extract_monthly_patsiondate_%sysfunc(date(030418_20180303235454).csv&lt;/P&gt;
&lt;P&gt;This may change every month how to hardcode this (date(030418_20180303235454)&lt;/P&gt;
&lt;P&gt;%sysfunc(date(030418_20180303235454)SourceFile1 = "der_extract_monthly_decisiondate_" &amp;amp; Convert_Date(Run_Date) &amp;amp; "*" &amp;amp; ".csv"&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;SourceFile1 = "der_extract_monthly_decisiondate_" &amp;amp; Convert_Date(Run_Date) &amp;amp; "*" &amp;amp; ".csv"&lt;BR /&gt;NewNameFile1 = "der_extract_monthly_decisiondate.csv"&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Do you know the ACTUAL name of the file you need to read?&amp;nbsp; Or do you just know the PATTERN of the file's name.&lt;/LI&gt;
&lt;LI&gt;Is it that the 'der_extract_monthly_patsiondate_' part is always the same and the 6 digit and 14 digit number parts vary?&amp;nbsp;
&lt;UL&gt;
&lt;LI&gt;Or is it the reverse?&amp;nbsp; That you know the digits and want to search existing files that have those digits in the name?&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Is the 6 digit part supposed to represent a date?&amp;nbsp; If so do you know the date? But perhaps not know the exact 14 digit part of te filename?&lt;/LI&gt;
&lt;LI&gt;Do you have multiple files with this same pattern of filenames in the same directory?&amp;nbsp; If so then how do you know which one you want to read?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;You need to explain in either other words or provide more repetitions of the pattern to help us understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 03:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/445376#M111591</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-14T03:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/445516#M111646</link>
      <description>&lt;P&gt;Actual Name of the file &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;STRONG&gt;030418_20180303235454&lt;/STRONG&gt;.csv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As this is the monthly file datetime cahnge every month.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 15:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/445516#M111646</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-14T15:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/447275#M112306</link>
      <description>&lt;P&gt;&lt;SPAN&gt;der_extract_monthly_&lt;/SPAN&gt;&lt;SPAN&gt;decisiondate&lt;/SPAN&gt;&lt;SPAN&gt;_030418_20180303235454.csv yes 6 digit and 14 digit part vary and file name remains the same. Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 22:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/447275#M112306</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-20T22:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Import csvusing macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/447281#M112311</link>
      <description>%lET FNAME = %SYSFUNC(CATS(DER_EXTRACT_MONTHLY_DECSIONDATE_,%SYSFUNC(TODAY(), MMDDYY6. ),_,%SYSFUNC(YEAR("&amp;amp;SYSDATE"D)),%SYSFUNC(MONTH("&amp;amp;SYSDATE"D)),%SYSFUNC(DAY("&amp;amp;SYSDATE"D)),%SYSFUNC(TIME(), HHMMSS6.),.CSV));&lt;BR /&gt;%PUT &amp;amp;FNAME.; i WAS TRYING TO GET THIS FINALLY RESOLVED IT, Thank you every one</description>
      <pubDate>Wed, 21 Mar 2018 00:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-using-macro-based-filename/m-p/447281#M112311</guid>
      <dc:creator>SAS_PA1</dc:creator>
      <dc:date>2018-03-21T00:23:06Z</dc:date>
    </item>
  </channel>
</rss>

