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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 869 views
  • 0 likes
  • 4 in conversation