<?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: Remove suffix filename in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950825#M371780</link>
    <description>&lt;P&gt;NO idea about what SAS Integration Studio can or cannot help with.&amp;nbsp; But it is simple with SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not clear what you actually are trying to do but let's just look at one command situation.&amp;nbsp; You receive periodic files all in the same structure and the NAME of the file has a value, say a DATE string, that does not exist as a variable in the file.&amp;nbsp; In that case you can use the FILENAME= option of the INFILE statement to the data step that reads the file create a temporary character variable that has the name of the file.&amp;nbsp; You can then extract the information from there and save it into a real variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So a data step like this could read ALL of the CSV files and make a single SAS dataset that now has DATE and ID as separate variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  length id $8 date 8 fname $200;
  format date yymmdd10.;
  infile 'class*.csv' dsd truncover filename=fname;
  input @;
  if fname ne lag(fname) then do;
    date = input(scan(fname,-1,'_').yymmdd8.);
    id = substr(scan(fname,-1,'_.'),8);
    delete;
  end;
  retain date id ;
  length var1 8 var2 $30 varlast 8;
  input (var1 -- varlast) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Nov 2024 17:58:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-11-14T17:58:20Z</dc:date>
    <item>
      <title>Remove suffix filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950808#M371768</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;we have csv files delivered with name *_&amp;lt;date&amp;gt;&amp;lt;id&amp;gt;. We want to easy rename the output files to * without suffix. Eg. class_20241114to class . How is that done in an easy way. We are running &amp;nbsp;Sas 9.4 on Linux. &amp;nbsp;We use Sas data integration studio. But can as well use the filesystem. We do not want &amp;nbsp;a shell script. But one command is fine. Thanks in advance for solutions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 17:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950808#M371768</guid>
      <dc:creator>AnnLyn</dc:creator>
      <dc:date>2024-11-14T17:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: Remove suffix filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950822#M371778</link>
      <description>&lt;P&gt;Does the file location where these CSV files reside &lt;STRONG&gt;ever&lt;/STRONG&gt; have more than one file in the folder with different suffixes?&lt;/P&gt;
&lt;P&gt;Such as class_20241114to and class_20241125ab?&lt;/P&gt;
&lt;P&gt;If so what name do you want as renaming both to "class" will basically lose one or more of the files involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you share why you need the suffix removed? It seems possible that you may lose information.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 17:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950822#M371778</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-11-14T17:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Remove suffix filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950825#M371780</link>
      <description>&lt;P&gt;NO idea about what SAS Integration Studio can or cannot help with.&amp;nbsp; But it is simple with SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not clear what you actually are trying to do but let's just look at one command situation.&amp;nbsp; You receive periodic files all in the same structure and the NAME of the file has a value, say a DATE string, that does not exist as a variable in the file.&amp;nbsp; In that case you can use the FILENAME= option of the INFILE statement to the data step that reads the file create a temporary character variable that has the name of the file.&amp;nbsp; You can then extract the information from there and save it into a real variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So a data step like this could read ALL of the CSV files and make a single SAS dataset that now has DATE and ID as separate variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  length id $8 date 8 fname $200;
  format date yymmdd10.;
  infile 'class*.csv' dsd truncover filename=fname;
  input @;
  if fname ne lag(fname) then do;
    date = input(scan(fname,-1,'_').yymmdd8.);
    id = substr(scan(fname,-1,'_.'),8);
    delete;
  end;
  retain date id ;
  length var1 8 var2 $30 varlast 8;
  input (var1 -- varlast) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Nov 2024 17:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950825#M371780</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-14T17:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Remove suffix filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950845#M371785</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  FILENAME='~/fff_tt';
  RC = rename( FILENAME
             , substr(FILENAME, 1, index(FILENAME, '_')-1)
             , 'file');
  putlog RC=;           
run;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Nov 2024 19:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950845#M371785</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-11-14T19:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Remove suffix filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950848#M371786</link>
      <description>&lt;P&gt;One statement would be something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %put rc = %sysfunc(rename( &amp;amp;FILENAME
         , %substr(&amp;amp;FILENAME, 1, %index(&amp;amp;FILENAME,_)-1)
         , file));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when the filename is stored in a macro variable.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 20:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950848#M371786</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-11-14T20:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Remove suffix filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950889#M371795</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465335"&gt;@AnnLyn&lt;/a&gt;&amp;nbsp;I assume you want to rename the file to a static name so you can use it with an external file reader transformation.&lt;/P&gt;
&lt;P&gt;It's years ago that I've used DIS but if I remember right then once you've created the external file metadata object it's possible to amend it to use a filename with a column modifier (&lt;SPAN&gt;&lt;EM&gt;class_:&lt;/EM&gt;) which then would work for any external file that fits the pattern. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I can't remember if this tweak needs to be done in the external file metadata or the file reader transformation. If you look at the generated code and then play a bit with DIS (=change something and inspect where the generated code changes) you should be able to figure it out.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 00:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-suffix-filename/m-p/950889#M371795</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-15T00:59:02Z</dc:date>
    </item>
  </channel>
</rss>

