<?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 Converting Excel spreadsheet cells into x commands to copy files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-Excel-spreadsheet-cells-into-x-commands-to-copy-files/m-p/780024#M248491</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an Excel spreadsheet with 4 columns. Each of the last 3 columns is formatted like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Column 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Column 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column 4&lt;/P&gt;
&lt;P&gt;Section 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; file_path&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;different_path&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; third path&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 file_name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 different_fname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 new_fname1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 second_file_name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 another_fname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 new_fname2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 more_fname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 new_fname3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Section 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each file name (and extension) listed under a file path is located within that file path. What I want to do is use these values to build a series of x commands which will copy each file from its original location to a new location.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a similar situation, I imported the Excel file using proc import and used a data _null_ step to set up a bunch of macro variables for each directory and file name using call symputx. However, in that case it was a bit simpler because there was a directory column and a corresponding file name column, so it was easy to just create macro variables for dir1 and fname1, dir2 and fname2, etc. This one is a bit more complex so I'm hoping to get some good ideas. What I need to end up with is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x " copy &amp;amp;file_path.\&amp;amp;file_name. new_directory_not_in_spreadsheet\&amp;amp;fname1."&lt;/P&gt;
&lt;P&gt;x " copy &amp;amp;file_path.\&amp;amp;second_file_name. new_directory_not_in_spreadsheet\&amp;amp;second_file_name."&lt;/P&gt;
&lt;P&gt;etc. for each file path/file name combo in columns 2-4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Fri, 12 Nov 2021 18:45:50 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2021-11-12T18:45:50Z</dc:date>
    <item>
      <title>Converting Excel spreadsheet cells into x commands to copy files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Excel-spreadsheet-cells-into-x-commands-to-copy-files/m-p/780024#M248491</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an Excel spreadsheet with 4 columns. Each of the last 3 columns is formatted like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Column 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Column 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column 4&lt;/P&gt;
&lt;P&gt;Section 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; file_path&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;different_path&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; third path&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 file_name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 different_fname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 new_fname1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 second_file_name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 another_fname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 new_fname2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 more_fname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 new_fname3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Section 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each file name (and extension) listed under a file path is located within that file path. What I want to do is use these values to build a series of x commands which will copy each file from its original location to a new location.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a similar situation, I imported the Excel file using proc import and used a data _null_ step to set up a bunch of macro variables for each directory and file name using call symputx. However, in that case it was a bit simpler because there was a directory column and a corresponding file name column, so it was easy to just create macro variables for dir1 and fname1, dir2 and fname2, etc. This one is a bit more complex so I'm hoping to get some good ideas. What I need to end up with is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x " copy &amp;amp;file_path.\&amp;amp;file_name. new_directory_not_in_spreadsheet\&amp;amp;fname1."&lt;/P&gt;
&lt;P&gt;x " copy &amp;amp;file_path.\&amp;amp;second_file_name. new_directory_not_in_spreadsheet\&amp;amp;second_file_name."&lt;/P&gt;
&lt;P&gt;etc. for each file path/file name combo in columns 2-4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 18:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Excel-spreadsheet-cells-into-x-commands-to-copy-files/m-p/780024#M248491</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2021-11-12T18:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Excel spreadsheet cells into x commands to copy files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Excel-spreadsheet-cells-into-x-commands-to-copy-files/m-p/780087#M248525</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 &amp;nbsp;set EXCL_IMPORT;
&amp;nbsp; call system('copy ' ||&amp;nbsp; catx('\',PATH,NAME) || ' ' || catx('\',PATH2,NAME2) );
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tweak to suit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Nov 2021 02:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Excel-spreadsheet-cells-into-x-commands-to-copy-files/m-p/780087#M248525</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-11-13T02:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Excel spreadsheet cells into x commands to copy files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Excel-spreadsheet-cells-into-x-commands-to-copy-files/m-p/780089#M248527</link>
      <description>&lt;P&gt;It is hard to tell some your example what your data is, but it looks like the first observation per SECTION value has the directory names and then the subsequent observations have filenames.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps your dataset looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length section $10 source dest1 dest2 $256 ;
  infile cards dsd dlm='|' truncover ;
  input section source dest1 dest2 ;
cards;
Section 1|c:\project1|d:\copy1|d:\copy2
Section 1|file1.sas|file2.sas|file3.sas
Section 1|file4.sas|file5.sas|file6.sas
Section 2|c:\project2|d:\copy3|d:\copy4
Section 2|file7.sas|file8.sas|file9.sas
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In which case you can use a data step like this to generate and execute two copy commands for every secondary observation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data commands;
  set have;
  by section;
  length cmd command1 command2 $600;
  if first.section then do;
     source_dir=source;
     dest_dir1=dest1;
     dest_dir2=dest2;
     retain source_dir dest_dir1 dest_dir2 ;
     delete;
  end;
  command1=catx(' ','copy',quote(catx('\',source_dir,source)),quote(catx('\',dest_dir1,dest1)));
  command2=catx(' ','copy',quote(catx('\',source_dir,source)),quote(catx('\',dest_dir2,dest2)));
  do cmd=command1,command2 ;
    infile cmd pipe filevar=cmd end=eof;
    do while (not eof);
      input;
      put _infile_;
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So for that example input here are the commands it would run.&lt;/P&gt;
&lt;PRE&gt;Obs     section                         command1                                             command2

 1     Section 1    copy "c:\project1\file1.sas" "d:\copy1\file2.sas"    copy "c:\project1\file1.sas" "d:\copy2\file3.sas"
 2     Section 1    copy "c:\project1\file4.sas" "d:\copy1\file5.sas"    copy "c:\project1\file4.sas" "d:\copy2\file6.sas"
 3     Section 2    copy "c:\project2\file7.sas" "d:\copy3\file8.sas"    copy "c:\project2\file7.sas" "d:\copy4\file9.sas"
&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Nov 2021 04:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Excel-spreadsheet-cells-into-x-commands-to-copy-files/m-p/780089#M248527</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-13T04:21:24Z</dc:date>
    </item>
  </channel>
</rss>

