<?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: using proc import to import excel file but use the files partial name in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810049#M33808</link>
    <description>&lt;P&gt;will do thank you!&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2022 23:45:52 GMT</pubDate>
    <dc:creator>sas_student1</dc:creator>
    <dc:date>2022-04-26T23:45:52Z</dc:date>
    <item>
      <title>using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/809926#M33801</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question on how to import an excel file where the excel file name has an ID and date that is changed on a daily basis.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get an excel file submitted to be the format of the naming convention of the file is that it has an ID (example 123 below) then the standard "excel_name" this doesn't change and then a date (e.g. 04252022 as below).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I read the file where if the file has the label "excel_name" regardless of the date and ID that it reads the file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC IMPORT 
OUT= directory
DATAFILE= "C:\user\123_excel_name_04252022" 
            DBMS=XLSX REPLACE;
     GETNAMES=YES;
	 sheet='directory';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 17:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/809926#M33801</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2022-04-26T17:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/809976#M33802</link>
      <description>&lt;P&gt;The following code will do. This will take the date on which the code is run.&lt;/P&gt;
&lt;P&gt;If your run the code today, the date value will be&amp;nbsp;&lt;SPAN&gt;04262022 and the file name will be&amp;nbsp;"c:\user\123_exel_name_04262022.xlsx".&amp;nbsp; if you do not need the file extension then remove the .xlsx from the code. But I think you will need it as excel files come with an extension.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT 
OUT= directory
DATAFILE= "C:\user\123_excel_name_%sysfunc(today(),mmddyyn8.).xlsx" 
            DBMS=XLSX REPLACE;
     GETNAMES=YES;
	 sheet='directory';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 18:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/809976#M33802</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-04-26T18:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/809998#M33803</link>
      <description>&lt;P&gt;You could use macro variables to build the filename.&lt;/P&gt;
&lt;P&gt;So first set the macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id=123;
%let date=%sysfunc(today(),mmddyy8.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use them to build the filename.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATAFILE= "C:\user\&amp;amp;id._excel_name_&amp;amp;date..xlsx" &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS It is not a good idea to use date string in MDY or DMY order in filenames.&amp;nbsp; The filenames will not sort in chronological order.&amp;nbsp; If you use date strings in YMD order instead then they will sort properly.&amp;nbsp; Plus you eliminate the confusion caused by values like 10122021. Is that Oct 12th or 10th of Dec?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 19:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/809998#M33803</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-26T19:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810002#M33804</link>
      <description>Are there multiple Excel files in the folder and you only want to read a specific one?&lt;BR /&gt;Is the file name always the day you run the code? Or is it always the most recent file?</description>
      <pubDate>Tue, 26 Apr 2022 19:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810002#M33804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-26T19:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810045#M33805</link>
      <description>&lt;P&gt;Good point there would end up being multiple files in one folder and I would want to get the most recent file that was saved. The way I get the file is that the sender adds a number and a date at the end. They have their own saving mechanism that they use. And this is something that I am trying to automate, so was thinking how to create an import that would be able to recognize the most recent file. Another item to note is that they would save the file at the end of day and then I wanted the code to pick it up the next day (I guess I can also have it run later in the evening so it doesn't have to wait the next day to run, but I allow the sender some time in case they decide to want to update the file after they have saved it.) I know its being complicated than it needs to be, but it got me to figure how "fancy" a sas code can one develop if one needed to.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 23:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810045#M33805</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2022-04-26T23:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810046#M33806</link>
      <description>&lt;P&gt;Thanks! This may work!. Though I wonder if I can add the %sysfunc(today(),mmddy8.) to the end of file name in the datafile step. That way I can have the one id macro. Would that not work as well?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess I can try it to see.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATAFILE= "C:\user\&amp;amp;id._excel_name_%sysfunc(today(),mmddy8)..xlsx" &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 23:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810046#M33806</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2022-04-26T23:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810048#M33807</link>
      <description>&lt;P&gt;Search the forum for how to import the most recent file in a folder. It's a question that's usually asked (and answered) at least once a month on here.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 23:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810048#M33807</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-26T23:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810049#M33808</link>
      <description>&lt;P&gt;will do thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 23:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810049#M33808</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2022-04-26T23:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810058#M33809</link>
      <description>Yes you can. Your code then will be.&lt;BR /&gt;PROC IMPORT &lt;BR /&gt;OUT= directory&lt;BR /&gt;DATAFILE= "C:\user\&amp;amp;id._excel_name_%sysfunc(today(),mmddyyn8.).xlsx" &lt;BR /&gt;            DBMS=XLSX REPLACE;&lt;BR /&gt;     GETNAMES=YES;&lt;BR /&gt;	 sheet='directory';&lt;BR /&gt;RUN;</description>
      <pubDate>Wed, 27 Apr 2022 02:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810058#M33809</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-04-27T02:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: using proc import to import excel file but use the files partial name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810073#M33811</link>
      <description>&lt;P&gt;&amp;lt;rant&amp;gt;Why do some ******, ****-******* ****** always come up with the stupid idea of using ANYTHING BUT a YMD date in filenames?&amp;lt;/rant&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, here's some code that extracts the date from filenames, converts it to a SAS date value and gets the max of it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indir=C:\user;

data _null_;
length dref $8 name $200;
rc = filename(dref,"&amp;amp;indir.");
did = dopen(dref);
if did
then do;
  do i = 1 to dnum(did);
    name = dread(did,i);
    if scan(name,2,"_") = "excel" and scan(name,3,"_") = "name" and scan(name,-1,".") = "xlsx"
    then do;
      date = input(scan(name,4,"_"),ddmmyy8.);
      if date &amp;gt; maxdate
      then do;
        maxdate = date;
        maxnum = scan(name,1,"_");
      end;
    end;
  end;
  if maxdate ne .
  then call symputx("infile",catx("_",maxnum,"excel","name",put(maxdate,ddmmyyn8.))!!".xlsx");
  else call symputx("infile","not found");
  rc = dclose(did);
end;
else call symputx("infile","directory not found");
rc = filename(dref);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With a properly structured filename, where the date comes before any variable part and has a date in YMD order, it's one simple one-liner:&lt;/P&gt;
&lt;P&gt;(UNIX example)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile "ls &amp;amp;indir./excel_name_*_*.xlsx|tail -1" pipe;
input;
call symputx("infile",_infile_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maxim 33: Intelligent Data Makes for Intelligent Programs.&lt;/P&gt;
&lt;P&gt;Filenames are &lt;EM&gt;data&lt;/EM&gt;, and properly structured filenames makes handling them a breeze.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 06:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-proc-import-to-import-excel-file-but-use-the-files-partial/m-p/810073#M33811</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-27T06:50:04Z</dc:date>
    </item>
  </channel>
</rss>

