When I run Code 1, it works perfectly.
I replaced an IP address instead of D directory in code 2, but not work as expected.
May I know why Code 2 is not working? Anyone can help on Code 2? Thank you very much.
Code 1:
%let cont=201802;
%put &cont;
data _null_;
x "copy "d:\test\&cont\*.txt" "d:\" ";
run;
Code 2:
%let cont=201802;
%put &cont;
data _null_;
x "copy "\\123.12.12.123\test\&cont\*.txt" "d:\" ";
run;
When I run Code 1, it didn't work, but it works perfectly for Code 2.
May I know why Code 1 is not working? Anyone can help on Code 1? Thank you very much.
Code 1:
%let cont=201802;
%put &cont;
data _null_;
x 'copy "d:\test\&cont\*.txt" "d:\"';
run;
Code 2:
data _null_;
x 'copy "d:\test\201802\*.txt" "d:\"';
run;
Macro variables are not expanded within single quotes. They must appear within double quotes to be expanded in a string.
Since this is a OS command, first step is to try those from a prompt with the same user as in the SAS session.
To see what external commands are really doing, use the filename pipe method:
%let cont=201802;
%put &cont;
filename oscmd pipe "copy \\123.12.12.123\test\&cont.\*.txt d:\ 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
PS the X statement does not need a data _null_ around it.
From the documentation: "The X statement is a global statement and executes as a DATA step is being compiled."
You can perfectly use it as a stand-alone statement, but it does not return any information besides &sysrc. The above code, OTOH, catches all responses and writes them to the SAS log.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.