Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Advice

Status
Not open for further replies.

nirmalraj

MIS
Apr 20, 2005
33
0
0
US
Hi All,

I have worked with normal macros but here I am trying to resolve a macro with an extension.

example:

% let x = 1243.txt;

Later down the program when I am trying to reference, it gives me an error stating syntax error.

y = &x;

Is there a way around it.

Thanks in advance,

Raj
 
You need to understand how macro variables work. When the line of code
Code:
  y = &x ;
is evaluated, SAS will determine what the macro variable X is and replace the &X in the code with the string that &X holds, and then compile the code. So, what the SAS compiler sees is this:-
Code:
  y = 1234.txt;
Which is obviously not correct, as strings need to be enclosed in quotes.
Remember though, single quotes ' ' mean a literal string, whereas double quotes " " still allows SAS to evaluate macros and macro variables.
Therefore your code should look like this:-
Code:
  y = "&x" ;

Enjoy.
 
Well Chris, It was not that either.I did have to get around it and truncated the .txt in unix and later cat with the .txt in sas job.

My assumption was no matter what is passed (put) in a string the macro variable to be able to return it when called but it does not happen so with a delimiter in it - atleast thats what i thought.

Thanks for your help.

- Raj
 
The delimiter should have no effect at all. There must be something else going on there.
Could you put up the exact line you used to set the macro variable, and the log for the section where you used it and I'll have a look. I frequently use macro variables for setting up filenames and libnames etc and have never had this problem.
Something else that is worth doing is putting this line just before you use the macro variable
Code:
%put macro variable X = &x ;
This will make sure that the macro variable is still what you expect it to be.
 
I don't know if this is your problem, but try setting up your %let statement as follows:

%let=%STR(1243.txt);

 
I'm still going with my original, "it's the quotes" theory.
Code:
%let x = 1234.txt;

* First do it the wrong way... *;
data _null_;
  y = &x;
  put y=;
run;

* Then do it the right way...*;
data _null_;
  y = "&x";
  put y=;
run;

Give this in the log:-
Code:
39   %let x = 1234.txt;
40
41   data _null_;
42     y = &x;
NOTE: Line generated by the macro variable "X".
1     1234.txt
           ---
           22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =,
              >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||,
              ~=.

43     put y=;
44   run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


45   data _null_;
46     y = "&x";
47     put y=;
48   run;

y=1234.txt
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

See, it works fine. Either it's the quotes, or something else is going on there. Best thing to do in situations like this is add in a step which writes out all the macro variable values to the log so you can check them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top