<?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 copy files from sub directory.. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235849#M55166</link>
    <description>&lt;P&gt;Is the directory structure you have mapped as "E-drive" &amp;nbsp;a NAS mount with an underlying Unix environment or is this a pure windows environment? &amp;nbsp;If it is Unix, a simple shell script could accomplish the task without a need for a lengthy and complex coding.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 21 Nov 2015 12:52:17 GMT</pubDate>
    <dc:creator>kannand</dc:creator>
    <dc:date>2015-11-21T12:52:17Z</dc:date>
    <item>
      <title>how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235842#M55165</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello friends,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Recently I'm working on a task where I need to take backup of all files which are generated as output from the main program to a new folder like Backup_2015 etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;my folder structure is like below -&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;E:\TEST DATA\2015&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;folder 2015 contains following files in it -&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. adomsg.sas7bdat&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. ADOMSG.XPT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Report_2015.rtf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. DOMAIN_XPT.LOG and &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. QC folder which again contains 3 files -&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a. notes.txt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b. QC_report.xlsx&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;c. Report.pdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;now my task is to take a backup these files by making a new folder in 2015 folder naming like Backup_2015(current year) and copy the contents of 2015 folder to it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have achieved the half milestone by below program however I'm not able to create "QC" folder and copy it's contents to newly created folder i.e. Backup_2015.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* SET THE OPTIONS */
OPTIONS MLOGIC MPRINT SYMBOLGEN;


%macro copyit(in=,out=);
filename in "&amp;amp;in";
filename out "&amp;amp;out";

/* copy the file byte-for-byte  */
data _null_;
  length filein 8 fileid 8;
  filein = fopen('in','I',1,'B');
  fileid = fopen('out','O',1,'B');
  rec = '20'x;
  do while(fread(filein)=0);
     rc = fget(filein,rec,1);
     rc = fput(fileid, rec);
     rc =fwrite(fileid);
  end;
  rc = fclose(filein);
  rc = fclose(fileid);
run;
 
filename in clear;
filename out clear;
%mend copyit;
/* Path for the source folder */
%let infolder=E:\TEST DATA\2015;
%let prot=backup; 
data dnam; 
rc=filename("mydir","&amp;amp;infolder"); /* create fileref */ 
did =dopen("mydir"); /* open folder */ 
f_name1=catx("_","&amp;amp;prot",(put(year(today()),best.)));
outfolder=dcreate(f_name1,"&amp;amp;infolder");/* create backup_&amp;lt;year&amp;gt; folder */
if did &amp;gt; 0 then
do i=1 to dnum(did);
file_name= dread(did,i);
infolder=catx("\","&amp;amp;infolder",dread(did,i)); /* read item name */
outfolder=catx("\","&amp;amp;infolder",f_name1,file_name) ;
output;
end;
rc=dclose(did); /* close folder */  
run;

/* create macro variable for input and out folder */
data _null_(drop=rc did f_name1 i);
	set dnam
	(where=(upcase(compress(f_name1))^=upcase(compress(file_name)))) end=eof;
	cnt+1;
	call symputx('infile'||LEFT(PUT(_N_,8.)),infolder);
	call symputx('outfile'||LEFT(PUT(_N_,8.)),outfolder);
	IF EOF THEN CALL SYMPUTX('CNT',PUT(_N_,8.));
run;

/* copy file one by one */
%macro doit;
	%do i=1 %to &amp;amp;cnt;
	%copyit(in=&amp;amp;&amp;amp;infile&amp;amp;i,out=&amp;amp;&amp;amp;outfile&amp;amp;i);
	%end;
%mend doit;

%doit&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Please help me to get this rigth.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in Advance!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Nikhil&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 09:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235842#M55165</guid>
      <dc:creator>nikhilwagh</dc:creator>
      <dc:date>2015-11-21T09:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235849#M55166</link>
      <description>&lt;P&gt;Is the directory structure you have mapped as "E-drive" &amp;nbsp;a NAS mount with an underlying Unix environment or is this a pure windows environment? &amp;nbsp;If it is Unix, a simple shell script could accomplish the task without a need for a lengthy and complex coding.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 12:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235849#M55166</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-21T12:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235892#M55170</link>
      <description>Hi Kannad,&lt;BR /&gt;thanks for you quick response. I'm testing these codes on Windows only however I need to release final SAS program to work on Unix environment. I will be very grateful if you explain me how to achive it with simple shell scripting.&lt;BR /&gt;Thanks.&lt;BR /&gt;- Nikhil</description>
      <pubDate>Sun, 22 Nov 2015 07:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235892#M55170</guid>
      <dc:creator>nikhilwagh</dc:creator>
      <dc:date>2015-11-22T07:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235899#M55173</link>
      <description>&lt;P&gt;I'm not an expert on Unix but this should work... The following would be the contents of your .sh file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;echo "starting backup process"
mkdir ./2015bk
mv ./2015/* ./2015bk
echo "Backup complete. The files have been copied. Please verify !"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note: This just creates a directory called 2015bk and copies the originals. &amp;nbsp;The original copies remain in the source as well. &amp;nbsp;If you need the original files or folders removed, you need to modify this to include a line performing the "rm" command to clear the files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps... Good Luck...!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2015 10:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235899#M55173</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-22T10:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235900#M55174</link>
      <description>&lt;P&gt;forgot to mention....The script assumes that the folder 2015 is available in the directory where the script is located and running... It will create a 2015bk folder in the same location where you have 2015 folder. If you need to run the copy from a different location, you need to specify the entire path in place of the "."&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2015 10:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235900#M55174</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-22T10:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235903#M55175</link>
      <description>Hey Kannad,&lt;BR /&gt;Your help is really appreciated, but I want to ask that can we added these codes in SAS program instead running it in Unix script or run manually?&lt;BR /&gt;&lt;BR /&gt;I want SAS to do this work for me as we are running single SAS program like&lt;BR /&gt;cd dmenv/dmwork/abc/ sas myprogram.sas&lt;BR /&gt;&lt;BR /&gt;Also I'm not much familiar with UNIX and scripting etc.&lt;BR /&gt;&lt;BR /&gt;I hope you understand it :).&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;BR /&gt;- Nikhil</description>
      <pubDate>Sun, 22 Nov 2015 13:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235903#M55175</guid>
      <dc:creator>nikhilwagh</dc:creator>
      <dc:date>2015-11-22T13:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235906#M55176</link>
      <description>&lt;P&gt;Nikhil - refer to the URL below, you'll get a better idea as it gives some theoritical background on how to do the same...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#xcomm.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#xcomm.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Focus on this example in &amp;nbsp;the document specifically that calls the macro pwdls: You can clone this to your requirement with the commands I gave you in the sh script earlier...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro pwdls;
%sysexec %str(pwd;ls -l);
%mend pwdls;
%pwdls;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Replace this line&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysexec %str(pwd;ls -l);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to &amp;nbsp;show something like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysexec %str(mkdir ./2015bk;mv ./2015/* ./2015bk);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps... Good Luck...!!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2015 14:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235906#M55176</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-22T14:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235907#M55177</link>
      <description>&lt;P&gt;As mentioned yesterday for the script, this code will work if you have and run the sas program in the same directory as the folder named 2015. If not, you need to code the entire path &amp;nbsp;in the %str() instead of referring to the current directory using a "."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this makes sense. &amp;nbsp;You may also need to refer to Unix help online just to get an idea of the Unix commands and the parameters used. This may help getting started...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://kb.iu.edu/d/afsk" target="_blank"&gt;https://kb.iu.edu/d/afsk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are plenty of online resources that can help learning Unix commands.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good Luck...!!!&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2015 14:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235907#M55177</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-22T14:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to copy files from sub directory..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235955#M55182</link>
      <description>&lt;P&gt;Alternatively, use version control software - which is what its created for. &amp;nbsp;After each run commit the folder to the repository and it is there for good. &amp;nbsp;Why go through all the effort of creating code to create multiple back up folders (which may or may not work depending on how robust your code is), then have to faff about with lots of folders/files including duplicates etc. when there is pre-built software to do it for you? &amp;nbsp;At worst case scenario your IT group should have a backup setup already.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 09:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-copy-files-from-sub-directory/m-p/235955#M55182</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-23T09:50:58Z</dc:date>
    </item>
  </channel>
</rss>

