What is wrong with my macro?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 88
Accepted Solution

What is wrong with my macro?

I am trying to do a VERY simply macro, and I can't figure out what is wrong!

 

%let medrec=FA_MEDREC;


data &medrec;
	infile 'C:\Users\t46837uhn\Documents\Med Rec\Med Rec Evaluation\round3\&medrec.csv'
        informat MRN best32.;
        format MRN best13.;
        input MRN;
run;

I keep getting the error in the log:

 

ERROR: Physical file does not exist, C:\Users\t46837uhn\Documents\Med Rec\Med Rec
       Evaluation\round3\&medrec.csv.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FA_MEDREC may be incomplete.  When this step was stopped there were 0
         observations and 255 variables.
WARNING: Data set WORK.FA_MEDREC was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.35 seconds
      cpu time            0.32 seconds

 But the file MOST DEFINITELY exists. I've triple checked that it is the correct name as well and in the right file path.

 

what the heck am I doing wrong?

 

I also tried doing:

 

%macro test (medrec=FA);


data &medrec;
	infile 'C:\Users\t46837uhn\Documents\Med Rec\Med Rec Evaluation\round3\&medrec.csv'
        informat MRN best32.;
        format MRN best13.;
        input MRN;
run;

%mend test;

But this also doesn't work.


Accepted Solutions
Solution
‎12-01-2016 12:16 PM
Contributor
Posts: 33

Re: What is wrong with my macro?

Try double quotes instead of the single ticks around your file path.

View solution in original post


All Replies
Solution
‎12-01-2016 12:16 PM
Contributor
Posts: 33

Re: What is wrong with my macro?

Try double quotes instead of the single ticks around your file path.
Frequent Contributor
Posts: 88

Re: What is wrong with my macro?

OMG!! soo annoying. Why SAS?? I spent like an hour trying to figure this stupid thing out. But sometimes single and double quotes are interchangeable!!! ugh!
Occasional Contributor
Posts: 7

Re: What is wrong with my macro?

Hi ,

 

It looks like the macro variable medrec is not resolving correctly on your infile statement due to the use of single quotation marks, so  if you tried using double quoation marks this will resolve the macro variable?

Super User
Posts: 6,935

Re: What is wrong with my macro?

Macro triggers (& or %) are not resolved in strings delimited by single quotes. Always use double quotes when macros or macro variables need to be resolved.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,490

Re: What is wrong with my macro?

You may need:

 

infile "C:\Users\t46837uhn\Documents\Med Rec\Med Rec Evaluation\round3\&medrec..csv"

Note the SECOND .

The first . will be treated as the end of a macro variable name.

 

See the difference between:

 

%put &medrec.csv;

%put &medrec..csv;

 

The first will not resolve to the external file name even after the quotes.

 

Also their is a very good reasons for the differences between " " and ' ' because you may have other code that is not intended to be a macro reference and you do not want the macro processor telling you that code bits that were not intended as macros references are an error.

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 237 views
  • 3 likes
  • 5 in conversation