Macro problem

Accepted Solution Solved
Reply
Super Contributor
Posts: 406
Accepted Solution

Macro problem

Hi Everyone,

I wrote the code below to import a number of data file to SAS.

However, it doesn't work. I think it is because of the path.

I am not sure how to fix it.

Could you please help me with that?

Many thanks as always.

HHC

%macro importdata (X=);

data &X;

infile 'D:\data\&X.csv' firstobs=3

delimiter=';' ;

   input date time  .....;

run;

%mend;

%importdata (X=data1);

%importdata (X=data2);


Accepted Solutions
Solution
‎03-11-2014 11:55 PM
PROC Star
Posts: 7,467

Re: Macro problem

Change your single quotes to be double quotes.  i.e.,

infile "D:\data\&X..csv" firstobs=3

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: Macro problem

infile 'D:\data\&X..csv' firstobs=3


two dots(.) instead of one. first dot (.) to make the macro variable boundary, the second dot(.) is the normal dot in file names.


Haikuo

Super Contributor
Posts: 406

Re: Macro problem

Thank you, Haikuo.

Somehow it still doesn't work.

The notice is: ERROR: Physical file does not exist, D:\data\&X..csv.

(when I replace &X with data1. it runs)

Can you guess what did I do wrong?

HHC

Solution
‎03-11-2014 11:55 PM
PROC Star
Posts: 7,467

Re: Macro problem

Change your single quotes to be double quotes.  i.e.,

infile "D:\data\&X..csv" firstobs=3

Super User
Posts: 7,757

Re: Macro problem

To expand on Arthur's answer:

Single quotes explicitly prevent the macro engine from interpreting anything that they enclose.

Only strings in double quotes allow the macro engine to go to work.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 406

Re: Macro problem

Posted in reply to KurtBremser

I am learning new thing all the time posted questions here.

Thank you Everyone for helping me from time to time!

I really appreciate it.

Have a nice day.

HHC

Super User
Posts: 7,757

Re: Macro problem

It's a pleasure!

Just don't forget to mark the question as answered.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
🔒 This topic is solved and locked.

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

Discussion stats
  • 6 replies
  • 229 views
  • 7 likes
  • 4 in conversation