<?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: renaming multiple pc files before importing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653563#M196327</link>
    <description>&lt;P&gt;Your server session may be in a lockdown state per administrative policies.&amp;nbsp; If so, the RENAME function may not work out of the box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p14axci3mo3egan1okbcydvbt433.htm&amp;amp;locale=en" target="_self"&gt;RENAME Docs&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;TABLE class="xisDoc-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xisDoc-summaryText"&gt;If the SAS session in which you are specifying the FILEEXIST function is in a locked-down state, and the pathname specified in the function has not been added to the lockdown path list, then the function will fail and a file access error related to the locked-down data will not be generated in the SAS log unless you specify the SYSMSG function.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Fri, 05 Jun 2020 11:56:41 GMT</pubDate>
    <dc:creator>RichardDeVen</dc:creator>
    <dc:date>2020-06-05T11:56:41Z</dc:date>
    <item>
      <title>renaming multiple pc files before importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653529#M196313</link>
      <description>&lt;P&gt;I am using EG which is running on GRID and I cant use PIPE.&lt;BR /&gt;I have to import monthly 10 txt files and manipulate them before exporting to CAS library for VA&lt;/P&gt;&lt;P&gt;Files are named from source:&lt;BR /&gt;HR002_Puudumised ja osalemised_2020-05-03-07-05-27.txt&lt;BR /&gt;HR009_Teenistusse tööle võetud_2020-05-03-07-20-29.txt&lt;BR /&gt;HR001_Isikkoosseisu nimekiri_2020-05-03-07-00-26.txt&lt;BR /&gt;HR025_Tekkepõhine palgakulu kontolaiendite lõikes_2020-05-10-07-40-04.txt&lt;BR /&gt;HR003_Staazid_2020-05-03-07-10-28.txt&lt;BR /&gt;HRxxx_Palga orienteeruv kokkuhoid_2020-05-03-07-45-35.txt&lt;BR /&gt;HR010_Lahkumised_2020-05-03-07-25-30.txt&lt;BR /&gt;HR014_Määratud palga aruanne_2020-05-03-07-30-31.txt&lt;BR /&gt;HR021_Koosseisuaruanne_2020-05-03-07-35-01.txt&lt;BR /&gt;HR005_Vakantsed ametikohad_2020-05-03-07-15-29.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;simple renaming works&lt;BR /&gt;data _null_;&lt;BR /&gt;rc=rename('/storage/sasdata/data03/users/andres.veer/HR009_Teenistusse tööle võetud_2020-05-03-07-20-29.txt', '/storage/sasdata/data03/users/andres.veer/HR009.txt', 'file');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i need help how to rename those original long names just to shorter names as&amp;nbsp;HR009.txt&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 07:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653529#M196313</guid>
      <dc:creator>veerand</dc:creator>
      <dc:date>2020-06-05T07:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: renaming multiple pc files before importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653540#M196316</link>
      <description>&lt;P&gt;If you can't use pipe, then you have to use the functions dopen, dread etc. in a data-step.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 08:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653540#M196316</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-06-05T08:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: renaming multiple pc files before importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653543#M196317</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;maybe this will work for you:&lt;/P&gt;
&lt;PRE&gt;%macro list_files(dir,ext);
  %local filrf rc did memcnt name i;
  %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
  %let did=%sysfunc(dopen(&amp;amp;filrf));      

   %if &amp;amp;did eq 0 %then %do; 
    %put Directory &amp;amp;dir cannot be open or does not exist;
    %return;
  %end;

   %do i = 1 %to %sysfunc(dnum(&amp;amp;did));   

   %let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

      %if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;
        %put &amp;amp;dir\&amp;amp;name;
         data _null_;
             rc = rename("&amp;amp;dir\&amp;amp;name", "&amp;amp;dir\%scan(&amp;amp;name.,1,_).&amp;amp;ext", 'file');
         run;

      %end;
      %else %if %qscan(&amp;amp;name,2,.) = %then %do;        
        %list_files(&amp;amp;dir\&amp;amp;name,&amp;amp;ext)
      %end;

   %end;
   %let rc=%sysfunc(dclose(&amp;amp;did));
   %let rc=%sysfunc(filename(filrf));     

%mend list_files;
options mprint;
%list_files(/storage/sasdata/data03/users/andres.veer/,txt);&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jun 2020 09:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653543#M196317</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2020-06-05T09:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: renaming multiple pc files before importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653549#M196321</link>
      <description>&lt;P&gt;Here is my code. I hope this could help you.&lt;/P&gt;&lt;P&gt;%macro rename_files(path=);&lt;BR /&gt;data a;&lt;BR /&gt;r=filename("fir","&amp;amp;path.");&lt;BR /&gt;d=dopen("fir");&lt;BR /&gt;if d&amp;gt;0 then do;&lt;BR /&gt;n=dnum(d);&lt;BR /&gt;do i=1 to n;&lt;BR /&gt;fname=dread(d,i);&lt;BR /&gt;if find(fname,".txt")&amp;gt;0 then do;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;c=dclose(d);&lt;BR /&gt;keep fname;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select count(*) into :n&lt;BR /&gt;from a&lt;BR /&gt;;&lt;BR /&gt;select fname into: fnames separated by "*"&lt;BR /&gt;from a&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;n.;&lt;BR /&gt;%let fname=%scan(&amp;amp;fnames.,&amp;amp;i.,*);&lt;BR /&gt;%let new_fname=%scan(&amp;amp;fname,1,_);&lt;/P&gt;&lt;P&gt;%put &amp;amp;fname.;&lt;BR /&gt;data _null_;&lt;BR /&gt;rc=rename("&amp;amp;path.\&amp;amp;fname.","&amp;amp;path.\&amp;amp;new_fname..txt", 'file');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend rename_files;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 09:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653549#M196321</guid>
      <dc:creator>Eigth_Below</dc:creator>
      <dc:date>2020-06-05T09:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: renaming multiple pc files before importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653550#M196322</link>
      <description>&lt;P&gt;Thank You very much Oligolas, it worked after minor replacements "\" to "/" as my GRID is on unix. Now reading your code, it is so obvious that I am mad that in two weeks I was not able to write it myself&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 10:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653550#M196322</guid>
      <dc:creator>veerand</dc:creator>
      <dc:date>2020-06-05T10:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: renaming multiple pc files before importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653563#M196327</link>
      <description>&lt;P&gt;Your server session may be in a lockdown state per administrative policies.&amp;nbsp; If so, the RENAME function may not work out of the box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p14axci3mo3egan1okbcydvbt433.htm&amp;amp;locale=en" target="_self"&gt;RENAME Docs&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;TABLE class="xisDoc-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xisDoc-summaryText"&gt;If the SAS session in which you are specifying the FILEEXIST function is in a locked-down state, and the pathname specified in the function has not been added to the lockdown path list, then the function will fail and a file access error related to the locked-down data will not be generated in the SAS log unless you specify the SYSMSG function.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 05 Jun 2020 11:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653563#M196327</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-06-05T11:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: renaming multiple pc files before importing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653619#M196334</link>
      <description>&lt;P&gt;I don't do much with EG and we don't have GRID, CAS or VA at all. I am not sure why you need to shorten the names. If long file names are the issue I would bring this to SAS as a tech support issue as I would expect to be able to read any valid file name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is the issue that you have multiple files that start the same an have the date as a difference in the name and just want a shorter "name" to use elsewhere in code that doesn't need to change?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 15:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-multiple-pc-files-before-importing/m-p/653619#M196334</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-05T15:09:29Z</dc:date>
    </item>
  </channel>
</rss>

