DATA Step, Macro, Functions and more

using robocopy in SAS to copy paths with special characters

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

using robocopy in SAS to copy paths with special characters

Hi

I'm using this macro to copy qlikview files with folder structure from one location to the other

 

%macro qvwrobocopydir (dir, archive);
%let datum = %sysfunc(date(),date7.);
  filename kopie pipe "robocopy %superq(dir) %superq(archive) *.qvw /MIR /Z /LOG:%superq(archive)\robocopy_&datum..log";
  data _null_;
    infile kopie;
    input;
    put _infile_;
  run;
%mend;
%qvwrobocopydir(f:\mainroot\Research & Development, g:\PROD\qvw_backup);

 

Despite the fact the folder f:\mainroot\Research & Development is used within the superq function the copy does not take place.

The & in the folder is the showstopper.

What can I do to circumvent this ? I already tried %nrstr(  but this does not help either.

Also I have access to both paths.

Any suggestions ?

Thanks

B


Accepted Solutions
Solution
‎02-16-2018 01:28 AM
SAS Employee
Posts: 19

Re: using robocopy in SAS to copy paths with special characters

Posted in reply to Billybob73

I think you need to pass the quotes down to the DOS command (when you invoke the macro) for the path spec to be formatted for Windows.  Here's the code snippet I tried:

 

1    %macro qvwrobocopydir (dir, archive);
2    %let datum = %sysfunc(date(),date7.);
3      filename kopie pipe "robocopy %superq(dir) %superq(archive) *.qvw /MIR /NP";
4      data _null_;
5        infile kopie;
6        input;
7        put _infile_;
8      run;
9    %mend;
10   %qvwrobocopydir("C:\temp\R & D", "C:\temp\backup");

NOTE: The infile KOPIE is:
      Unnamed Pipe Access Device,
      PROCESS=robocopy "C:\temp\R & D" "C:\temp\backup" *.qvw /MIR /NP,
      RECFM=V,LRECL=32767


-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Thursday, February 15, 2018 2:43:19 PM
   Source : C:\temp\R & D\
     Dest : C:\temp\backup\

    Files : *.qvw
	
  Options : /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /NP /R:1000000 /W:30

------------------------------------------------------------------------------

	                   3	C:\temp\R & D\
	    New File  		   14378	test1.qvw
	    New File  		  104890	test2.qvw
	    New File  		  100536	test3.qvw

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         3         3         0         0         0         0
   Bytes :   214.6 k   214.6 k         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :            24422666 Bytes/sec.
   Speed :            1397.476 MegaBytes/min.
   Ended : Thursday, February 15, 2018 2:43:19 PM
NOTE: 33 records were read from the infile KOPIE.
      The minimum record length was 0.
      The maximum record length was 81.
NOTE: DATA statement used (Total process time):
      real time           0.11 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              1086.53k
      OS Memory           9196.00k
      Timestamp           02/15/2018 02:43:19 PM
      Step Count                        1  Switch Count  0

View solution in original post


All Replies
Super User
Super User
Posts: 9,200

Re: using robocopy in SAS to copy paths with special characters

Posted in reply to Billybob73

Well, I hate to point out the obvious, but putting special characters in paths is a pretty bad thing to do from both programming an system point of view.  Maxim 44:

https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers...

 

As a note, you could just stream text files through a datastep to effect a copy.  

Super User
Posts: 22,827

Re: using robocopy in SAS to copy paths with special characters

[ Edited ]
Posted in reply to Billybob73

Look up the FCOPY function. 

 


Billybob73 wrote:

Hi

I'm using this macro to copy qlikview files with folder structure from one location to the other

 

%macro qvwrobocopydir (dir, archive);
%let datum = %sysfunc(date(),date7.);
  filename kopie pipe "robocopy %superq(dir) %superq(archive) *.qvw /MIR /Z /LOG:%superq(archive)\robocopy_&datum..log";
  data _null_;
    infile kopie;
    input;
    put _infile_;
  run;
%mend;
%qvwrobocopydir(f:\mainroot\Research & Development, g:\PROD\qvw_backup);

 

Despite the fact the folder f:\mainroot\Research & Development is used within the superq function the copy does not take place.

The & in the folder is the showstopper.

What can I do to circumvent this ? I already tried %nrstr(  but this does not help either.

Also I have access to both paths.

Any suggestions ?

Thanks

B


 

Solution
‎02-16-2018 01:28 AM
SAS Employee
Posts: 19

Re: using robocopy in SAS to copy paths with special characters

Posted in reply to Billybob73

I think you need to pass the quotes down to the DOS command (when you invoke the macro) for the path spec to be formatted for Windows.  Here's the code snippet I tried:

 

1    %macro qvwrobocopydir (dir, archive);
2    %let datum = %sysfunc(date(),date7.);
3      filename kopie pipe "robocopy %superq(dir) %superq(archive) *.qvw /MIR /NP";
4      data _null_;
5        infile kopie;
6        input;
7        put _infile_;
8      run;
9    %mend;
10   %qvwrobocopydir("C:\temp\R & D", "C:\temp\backup");

NOTE: The infile KOPIE is:
      Unnamed Pipe Access Device,
      PROCESS=robocopy "C:\temp\R & D" "C:\temp\backup" *.qvw /MIR /NP,
      RECFM=V,LRECL=32767


-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Thursday, February 15, 2018 2:43:19 PM
   Source : C:\temp\R & D\
     Dest : C:\temp\backup\

    Files : *.qvw
	
  Options : /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /NP /R:1000000 /W:30

------------------------------------------------------------------------------

	                   3	C:\temp\R & D\
	    New File  		   14378	test1.qvw
	    New File  		  104890	test2.qvw
	    New File  		  100536	test3.qvw

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         3         3         0         0         0         0
   Bytes :   214.6 k   214.6 k         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :            24422666 Bytes/sec.
   Speed :            1397.476 MegaBytes/min.
   Ended : Thursday, February 15, 2018 2:43:19 PM
NOTE: 33 records were read from the infile KOPIE.
      The minimum record length was 0.
      The maximum record length was 81.
NOTE: DATA statement used (Total process time):
      real time           0.11 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              1086.53k
      OS Memory           9196.00k
      Timestamp           02/15/2018 02:43:19 PM
      Step Count                        1  Switch Count  0
Contributor
Posts: 55

Re: using robocopy in SAS to copy paths with special characters

Posted in reply to DaveHorne

Thanks Dave ! This works !

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 140 views
  • 0 likes
  • 4 in conversation