Macro Question

Accepted Solution Solved
Reply
Regular Contributor
Posts: 173
Accepted Solution

Macro Question

Hello Everyone,

I am trying to copy a file from one Unix directory to another Unix directory using a SAS macro.  My code listed below without the macro works.  But the macro doesn't work.  There is no error in the log and the file on Unix is not copied.   I am using a macro because i have alot of files to work with.

Thank you very much for any input!

(WORKS)

rsubmit;

x "cd /home/users/";

x "cp cust_20120106.sas7bdat /home/users/mydir/";

endrsubmit;

(DOES NOT WORK)

rsubmit;

%macro test(file_date);

x "cd /home/users/";

x "cp cust_&file_date.sas7bdat /home/users/mydir/";

%mend test;

%test(20120106);

endrsubmit;


Accepted Solutions
Solution
‎11-15-2012 01:43 PM
Super User
Posts: 11,343

Re: Macro Question

Your line:

x "cp cust_&file_date.sas7bdat /home/users/mydir/";

should read

x "cp cust_&file_date..sas7bdat /home/users/mydir/";

The . is used by the macro processor to say "append the following text to the result of the macro variable" so you need one more for the file extension.

In this case the result was "cp cust_20120106sas7bdat (etc)

View solution in original post


All Replies
Super User
Posts: 19,861

Re: Macro Question

have you looked at proc datasets and move or copy options instead?

Or does that not work with Unix?

Solution
‎11-15-2012 01:43 PM
Super User
Posts: 11,343

Re: Macro Question

Your line:

x "cp cust_&file_date.sas7bdat /home/users/mydir/";

should read

x "cp cust_&file_date..sas7bdat /home/users/mydir/";

The . is used by the macro processor to say "append the following text to the result of the macro variable" so you need one more for the file extension.

In this case the result was "cp cust_20120106sas7bdat (etc)

Regular Contributor
Posts: 173

Re: Macro Question

Thank you guys for your response!

Ballardw,

Your suggestion worked beautifully!  I really appreciate it.

Thank you! Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 182 views
  • 0 likes
  • 3 in conversation