DATA Step, Macro, Functions and more

Using IP address in X statement

Reply
Frequent Contributor
Frequent Contributor
Posts: 78

Using IP address in X statement

[ Edited ]

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;

Super User
Posts: 5,849

Re: Using IP address in X statement

[ Edited ]

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
Super User
Posts: 9,855

Re: Using IP address in X statement

[ Edited ]

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Frequent Contributor
Posts: 78

Using IP address in X statement

[ Edited ]

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;

Esteemed Advisor
Posts: 5,474

Re: Using IP address in X statement

[ Edited ]

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

PG
Ask a Question
Discussion stats
  • 4 replies
  • 123 views
  • 0 likes
  • 4 in conversation