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"';
@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;
How about doing this without X command?
https://core.sasjs.io/mp__copyfolder_8sas.html
x 'cp "&rep_bloctel_retour./*.*" "&RacineRun./&RacineBloctel./archive"';
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.