BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

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;

4 REPLIES 4
scb
Obsidian | Level 7 scb
Obsidian | Level 7

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;

PGStats
Opal | Level 21

Macro variables are not expanded within single quotes. They must appear within double quotes to be expanded in a string.

PG
LinusH
Tourmaline | Level 20

Since this is a OS command, first step is to try those from a prompt with the same user as in the SAS session.

Data never sleeps
Kurt_Bremser
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1686 views
  • 0 likes
  • 4 in conversation