<?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: Read invoice number from filename in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399024#M96590</link>
    <description>You can use the scan function to extract the invoice number from the filename. Within a data step:&lt;BR /&gt;invoice_no = scan(filename_var, 4, "_.");&lt;BR /&gt;&lt;BR /&gt;Depending on what you already have, a better solution may exist.</description>
    <pubDate>Wed, 27 Sep 2017 05:02:34 GMT</pubDate>
    <dc:creator>error_prone</dc:creator>
    <dc:date>2017-09-27T05:02:34Z</dc:date>
    <item>
      <title>Read invoice number from filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/398957#M96575</link>
      <description>&lt;P&gt;Hello SAS Gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help to extract number from a invoice file the vendor sends every month and have it as a variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;invoice_01jan2017_31Jan2017_4567.xlsx --&amp;gt; January file&lt;/P&gt;&lt;P&gt;invoice__01feb2017_28Feb2017_4678.xlsx&amp;nbsp; --&amp;gt; feburary file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is(in addition to bunch of fields within the file):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Month&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;invoice_no&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Jan&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4567&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Feb&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4678&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to prgrammatically read the invoice number from the filename every month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 21:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/398957#M96575</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-09-26T21:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Read invoice number from filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/398959#M96576</link>
      <description>&lt;P&gt;How do you read the data? And what is the name after you read it into SAS? Code examples would be the best way to answer.&lt;/P&gt;
&lt;P&gt;I ask because there are a number of ways that may be very easy depending on the answers to these questions.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 21:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/398959#M96576</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-26T21:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Read invoice number from filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399024#M96590</link>
      <description>You can use the scan function to extract the invoice number from the filename. Within a data step:&lt;BR /&gt;invoice_no = scan(filename_var, 4, "_.");&lt;BR /&gt;&lt;BR /&gt;Depending on what you already have, a better solution may exist.</description>
      <pubDate>Wed, 27 Sep 2017 05:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399024#M96590</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-09-27T05:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Read invoice number from filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399150#M96644</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have been using to import the file right now. But I am not able to read the invoice number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	day=today();
	call symput("begmnth",put(intnx("month",day,-8,'b'),date9.));
run;

%put &amp;amp;=begmnth.;

filename invoice "&amp;amp;path./invoice_&amp;amp;begmnth.*";

proc import out= want 
  datafile=invoice dbms= xlsx replace;
  startrow=3; 
  Sheet = 'Sheet1'; 
  Getnames = No; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Sep 2017 13:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399150#M96644</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-09-27T13:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Read invoice number from filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399176#M96657</link>
      <description>&lt;P&gt;So if you have already have a pattern for finding the filename then you could use that to also get the actual filename and parse out the invoice part as save it as a macro varaible. You could also save the physical filename as a macro variable and use that directly in the IMPORT step instead of the fileref.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   length filename $256 ;
   infile "&amp;amp;path./invoice_&amp;amp;begmnth.*" filename=filename ;
   input @;
   invoice = scan(filename,-2,'._');
   call symputx('filename',quote(trim(filename));
   call symputx('invoice',invoice);
   stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you can then use in your other code to read the data. For example you could add a data step to add variables with the invoice number and beginning date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import out= want replace
  datafile=&amp;amp;filename dbms= xlsx ;
  startrow=3; 
  Sheet = 'Sheet1'; 
  Getnames = No; 
run;

data want ;
   invoice=&amp;amp;invoice ;
   begmnth= "&amp;amp;begmnth"d ;
   format begmnth date9. ;
   set want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 14:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399176#M96657</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-27T14:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Read invoice number from filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399192#M96667</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;This is exactly what I was looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 14:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399192#M96667</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-09-27T14:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Read invoice number from filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399193#M96668</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43025"&gt;@error_prone&lt;/a&gt;&amp;nbsp;for the right direction&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 14:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-invoice-number-from-filename/m-p/399193#M96668</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-09-27T14:39:11Z</dc:date>
    </item>
  </channel>
</rss>

