DATA Step, Macro, Functions and more

x command with macro variable

Reply
Occasional Contributor
Posts: 15

x command with macro variable

Hi There,

 

I ecountered this issue when I tried to use X command to open a file and file name has a macro variable: &basedt2.

 

X '"C:\Ma Project\01 Angeliebe daily tracking\raw data\ReportCustomerCsv-&basedt2..csv"';

 

It can not be executed.

 

Does anyone have a solution?

 

Thanks!

 

 

Super User
Posts: 6,936

Re: x command with macro variable

What ERROR message did you get?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,401

Re: x command with macro variable

Two things, first you need to put

options mlogic symbolgen mprint;

 

Before that call and see what the macro variable relates to.  Then check that file exists - simple way of checking is to open a cmd window, then copy an dpaste the full text (not the macro variable) into the cmd window and see what it says.  Likely the path is wrong, or you have spaces.  Also note where you are running it.  It will have to be on a windows machine and have Excel installed and associated with .csv, otherwise the OS does not know what software to open it with.

 

And a final question, why?  It seems totally pointless to open file on the OS.

Super User
Posts: 17,813

Re: x command with macro variable

Why do you have single and double quotes? 

Use only the double quotes. 

Super User
Posts: 6,936

Re: x command with macro variable

@Reeza look closely. There are blanks in the pathname.

 

Kurt's computing mantra #2: Blanks in filenames are a BAD IDEA.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,081

Re: x command with macro variable

Where is the command?  You have a path to a file, but X requires a system-based command that it will execute.  

 

Are you saying this command sometimes does what you want if you don't refer to a macro variable within?

Super User
Super User
Posts: 7,401

Re: x command with macro variable

Well, not quite @Astounding.  If the file type is known by the system, in this case CSV is associated with Excel, then it actually opens Excel and then file.  Thats why I was questioning the reason behind it, opening the file, as SAS already has the options results which will open output files when created.

Ask a Question
Discussion stats
  • 6 replies
  • 373 views
  • 0 likes
  • 5 in conversation