SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
MILKYLOVE
Calcite | Level 5

Hello I have this piece of code below where I am trying to copy ALL files from one directory to another, but the nothing happens when I run the code. Any idea why?

 

%let RacineRun = /sasprep/fit/fit_1/run/azi/d2d/w6;
%let RacineBloctel = /particuliers/bloctel/fichiers;
%let REP_BLOCTEL_RETOUR = /sasprep/prep/cft/w6/BLOCTEL/ENTRANT;

x 'cp "&rep_bloctel_retour./*" "&RacineRun./&RacineBloctel./archive"';
4 REPLIES 4
Tom
Super User Tom
Super User

@MILKYLOVE wrote:

Hello I have this piece of code below where I am trying to copy ALL files from one directory to another, but the nothing happens when I run the code. Any idea why?

 

%let RacineRun = /sasprep/fit/fit_1/run/azi/d2d/w6;
%let RacineBloctel = /particuliers/bloctel/fichiers;
%let REP_BLOCTEL_RETOUR = /sasprep/prep/cft/w6/BLOCTEL/ENTRANT;

x 'cp "&rep_bloctel_retour./*" "&RacineRun./&RacineBloctel./archive"';

The macro processor will ignore strings that are bounded by single quote characters.

Use double quote characters instead.

 

I also normally avoid the X command as you have no way to check any messages it might be trying to send you.

data _null_;
  input "cp ""&rep_bloctel_retour./*"" ""&RacineRun./&RacineBloctel./archive""" pipe;
  input;
  put _infile_;
run;
AllanBowe
Barite | Level 11

How about doing this without X command?

https://core.sasjs.io/mp__copyfolder_8sas.html

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
Ksharp
Super User
x 'cp "&rep_bloctel_retour./*.*" "&RacineRun./&RacineBloctel./archive"';
Kurt_Bremser
Super User

KISS (Keep It Simple, Stupid) principle: since your path names have no blanks, no quotes are needed around them.

Macro triggers will not be resolved inside single quotes.

And the X statement is a very crude tool, not giving you any more information than the return code in &SYSRC.

 

In light of this, do

%let RacineRun = /sasprep/fit/fit_1/run/azi/d2d/w6;
%let RacineBloctel = particuliers/bloctel/fichiers; /* you use a slash later when you call the macro variable */
%let REP_BLOCTEL_RETOUR = /sasprep/prep/cft/w6/BLOCTEL/ENTRANT;

data _null_;
infile "cp &rep_bloctel_retour./* &RacineRun./&RacineBloctel./archive 2>&1" pipe;
input;
put _infile_;
run;

The INFILE PIPE method shown here retrieves all responses from the external command to the SAS log. The 2>&1 at the end of the command reroutes stderr to stdout, so the pipe catches "normal" and error messages.

If you still get issues, post the complete log from the above code.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1362 views
  • 1 like
  • 5 in conversation