<?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: How to rename split files from 'aa' to 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835636#M330358</link>
    <description>&lt;P&gt;Why are they getting named that way to begin with?&amp;nbsp; Is it because that is how the Unix command split names the files?&amp;nbsp; Is there an option to change how it names the files so it numbers them instead appending letters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not why not just split the files yourself instead of calling that Unix command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let infile=big.txt ;
%let outbase=small ;
data _null_;
   fileno+1;
   infile "&amp;amp;infile" ;
   outfile=cats("&amp;amp;outbase._",fileno,'.txt');
   do row=1 to 350000;
      input ;
      file out filevar=outfile ;
      put _infile_;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Sep 2022 15:17:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-28T15:17:12Z</dc:date>
    <item>
      <title>How to rename split files from 'aa' to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835588#M330337</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large csv file blc_20220602_20220601220525.csv that I split into different files of 350,000 lines. However, after splitting the files,&lt;/P&gt;&lt;P&gt;I am left with these names:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MILKYLOVE_0-1664368563542.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75680iE9DA16E6963D0CD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MILKYLOVE_0-1664368563542.png" alt="MILKYLOVE_0-1664368563542.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of 'aa', 'ab', 'ac', How can I name my split files into&lt;/P&gt;&lt;P&gt;blc_20220602_20220601220525&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;_1&lt;/STRONG&gt;&lt;/FONT&gt;.csv&lt;/P&gt;&lt;P&gt;blc_20220602_20220601220525&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;_2&lt;/FONT&gt;&lt;/STRONG&gt;.csv&lt;/P&gt;&lt;P&gt;blc_20220602_20220601220525&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;_3&lt;/FONT&gt;&lt;/STRONG&gt;.csv&lt;/P&gt;&lt;P&gt;etc...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let blc = c:/myfiles/blc;


/* ************* Construction of macro "SPLIT" ************* */
%macro split_unix(fichier_complet=,
                          taille_split=, 
                          out=);
%let fichier = %scan(&amp;amp;fichier_complet,-1,/);
%let path = %substr(&amp;amp;fichier_complet,1,%index(&amp;amp;fichier_complet,&amp;amp;fichier)-1);
%let fic = %scan(&amp;amp;fichier,1,.);
%let extension = %scan(&amp;amp;fichier,2,.);

%global cr_split;
%let cr_split=0;

%put path = &amp;amp;path;
%put fichier = &amp;amp;fichier;
%put fic = &amp;amp;fic;
%put extension = &amp;amp;extension;
%put &amp;amp;fic..&amp;amp;extension;

/* *********** Verify if the file is empty *********** */
%let list_fic_vide =;
%let flag_vide =;
filename rep_cn pipe "wc -l &amp;amp;path./&amp;amp;fichier";

/* ************ Verify if the file exceeds the limit ************ */
%let count_row = 0;

data rep_cn;
    infile rep_cn dsd truncover;
    input var:$250.;
    if not find(lowcase(var),"total");
    count = input(scan(var,1," "),20.);
    fic = scan(var,-1,"/");
run;

proc sql noprint;
    select "KO", fic into :flag_vide, :list_fic_vide separated by " - "
    from rep_cn where count &amp;lt;= 1;
     
     select max(count) into: count_row
     from rep_cn group by fic;
quit;

%put List of empty files : &amp;amp;list_fic_vide.;
%put Max volume is : &amp;amp;count_row. nombre de lignes;
/* **************************** */

%if &amp;amp;flag_vide ne KO and &amp;amp;count_row. &amp;gt; %scan(&amp;amp;taille_split,2) %then %do;
     x "cd &amp;amp;path";
     systask command "split &amp;amp;taille_split &amp;amp;fic..&amp;amp;extension &amp;amp;fic" wait status=fg_split;

     %put CR Unix du split est : &amp;amp;fg_split;

     %if not &amp;amp;fg_split &amp;gt; 0 %then %do;
          filename list_fic pipe "find . ! -name '*.&amp;amp;extension' -a -name '*&amp;amp;fic*'";

          data temp;
                infile list_fic missover truncover dsd;
                input var:$50.;
                var = scan(var,2,"/");
          run;

          data _null_;
                set temp end=fin;
                call symputx(compress('split'||put(_n_,3.)),var,'g');
                if fin then call symputx('nbre',put(_n_,3.));
          run;

          %do i = 1 %to &amp;amp;nbre;
                %put split&amp;amp;i = &amp;amp;&amp;amp;split&amp;amp;i;
                x "mv &amp;amp;&amp;amp;split&amp;amp;i ./&amp;amp;out/&amp;amp;&amp;amp;split&amp;amp;i...&amp;amp;extension";
                %let cr_split=%eval(&amp;amp;cr_split+&amp;amp;sysrc);
          %end;
     %end;
%end; /* Fin %if &amp;amp;flag_vide ne KO */
%else %do;
     %let cr_split=1;
%end;
%mend;
/* ************************************************************** */

%macro boucle_lancement(chemin=,fic_a_split=);
     filename fic pipe "ls &amp;amp;chemin/&amp;amp;fic_a_split.";

     data _null_;
          infile fic missover truncover end=fin;
          input fic:$100.;
          call symputx(compress('fic'||put(_n_,3.)),fic,'g');
          if fin then call symputx('nbre_fic',put(_n_,3.),'g');
     run;

     %do nb = 1 %to &amp;amp;nbre_fic;
          %split_unix(fichier_complet=&amp;amp;&amp;amp;fic&amp;amp;nb,
                          taille_split=-l 350000, 
                          out=);
                          
          %if &amp;amp;cr_split eq 0 %then %do;
                x "rm &amp;amp;&amp;amp;fic&amp;amp;nb";
          %end;
     %end;
     
%mend;

%boucle_lancement(chemin=&amp;amp;blc.,
                          fic_a_split=blc_*.csv);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 12:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835588#M330337</guid>
      <dc:creator>MILKYLOVE</dc:creator>
      <dc:date>2022-09-28T12:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename split files from 'aa' to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835636#M330358</link>
      <description>&lt;P&gt;Why are they getting named that way to begin with?&amp;nbsp; Is it because that is how the Unix command split names the files?&amp;nbsp; Is there an option to change how it names the files so it numbers them instead appending letters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not why not just split the files yourself instead of calling that Unix command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let infile=big.txt ;
%let outbase=small ;
data _null_;
   fileno+1;
   infile "&amp;amp;infile" ;
   outfile=cats("&amp;amp;outbase._",fileno,'.txt');
   do row=1 to 350000;
      input ;
      file out filevar=outfile ;
      put _infile_;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2022 15:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835636#M330358</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-28T15:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename split files from 'aa' to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835773#M330438</link>
      <description>&lt;P&gt;Yes, I think the systask command split just names the files with alphabets by default.&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's why I'm trying to find a way to change the name or maybe use another method.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 06:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835773#M330438</guid>
      <dc:creator>MILKYLOVE</dc:creator>
      <dc:date>2022-09-29T06:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename split files from 'aa' to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835817#M330466</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Assuming you are under Windows OS.
If your OS is Linux/Unix ,try to use LS command to repalce DIR command
*/

%let path_in=  c:\temp\ ;  


filename x pipe %sysfunc(quote(dir "&amp;amp;path_in."\*.csv /s /b));
data x;
 infile x truncover;
 input old $2000.;
if prxmatch('/^_\d+/',scan(old,-1,'/\')) then do;
n+1;
new=prxchange('s/[\.a-z]+$//i',1,strip(old));
new=cats("&amp;amp;path_in.\blc",scan(new,-1,'/\'),'_',n,'.csv');
rc=rename(strip(old),strip(new),'file');
end;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Sep 2022 12:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835817#M330466</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-29T12:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename split files from 'aa' to 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835840#M330470</link>
      <description>&lt;P&gt;I already showed you how to generate the split files with numeric suffixes using a different method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to rename the existing files then first get the list of files into data.&amp;nbsp; Say you have the list in a dataset named FILES and the filename is in a variable named FILENAME.&amp;nbsp; Then you could use code like this to generate NEW_NAME variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table rename_files
  select substr(filename,1,length(filename)-6) as basename
       , count(*) as n_files
       , filename
  group by 1
   having count(*) &amp;gt; 1 
;
quit;

data rename_files;
   do suffix=1 by 1 until(last.basename);
      set rename_files;
      by basename;
      new_name = cats(basename,putn(suffix,cats(Z,length(cats(n_files)),'.'),'.csv');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;output;
&amp;nbsp;&amp;nbsp;&amp;nbsp;end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then use that list to generate code to move, rename or copy the files.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 13:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-split-files-from-aa-to-1/m-p/835840#M330470</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-29T13:44:31Z</dc:date>
    </item>
  </channel>
</rss>

