BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Saugata
Obsidian | Level 7

Hi,

I am trying something very simple. Just cutting a file (for example doc file) from one loacation and pasting it to another using X command. This should not be a problem but whenever I am using a Macro variable to resolve folder location I am facing problems.

The simple code is:

'move "C:\Data\Learning Products\New Folder\New Microsoft Word Document.doc" "C:\Data\Learning Products"';

This is running perfectly and giving me desired results.

But when I am running the same code using Macro variables:

%let abc=New Folder;

%let xyz=New Microsoft Word Document.doc;

X 'move "C:\Data\Learning Products\&abc.\&xyz" "C:\Data\Learning Products"';

This Code is not working and in the DOS window I am getting: 'The System could not find the file specified' error.

Can anyone please point out the error I am making in the second code?

Thanks in advance for your effort.

1 ACCEPTED SOLUTION

Accepted Solutions
polingjw
Quartz | Level 8

The problem is that the macro variables are not resolved inside the single quote marks.  Try using this:

x %unquote(%str(%')move "C:\Data\Learning Products\&abc\&xyz" "C:\Data\Learning Products"%str(%'));

View solution in original post

4 REPLIES 4
polingjw
Quartz | Level 8

The problem is that the macro variables are not resolved inside the single quote marks.  Try using this:

x %unquote(%str(%')move "C:\Data\Learning Products\&abc\&xyz" "C:\Data\Learning Products"%str(%'));

Saugata
Obsidian | Level 7

Thanks polingjw it worked like a charm.

polingjw
Quartz | Level 8

I just thought of an easier solution.  Just remove the single quotes from your original X statement, as this syntax is not required.

Ksharp
Super User

It is very intesting .

Another workaround way is to make a .bat file ,then use X command to execute it.

%let a=Task temp;
%let b=file.pdf;
data _null_;
 file 'c:\a.bat';
 a=catt('move "c:\',symget('b'),'" "c:\',symget('a'),'" ');
 put a;
run;
options noxwait;
x 'c:\a.bat';
x 'del c:\a.bat';

Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1064 views
  • 0 likes
  • 3 in conversation