DATA Step, Macro, Functions and more

Using %Let in text file

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Using %Let in text file

Hi all,

I have a txt file called mytext that has the following:

%LET name1=Customers;

And then in my SAS program I have:

filename macro1 "C:\mytext.txt";

%include macro1;

create table mylib.&name1_new as select * from
connection to oracle(

select *
from old_customers
);

run;

Everything in the my SAS program works However, I'm getting a "WARNING: symbolic reference error for name1 not resolved." Is the problem the macro setup in the text file?

Thanks.


Accepted Solutions
Solution
‎09-30-2014 12:38 PM
Occasional Contributor
Posts: 16

Re: Using %Let in text file

Ok I think I figured it out.

I had to place the below inside my proc sql statement.  Before it was was sitting outside and most likely not in the same "scope".

filename macro1 "C:\mytext.txt";

%include macro1;

Unless there is a better way of doing it.  Thanks.

View solution in original post


All Replies
N/A
Posts: 1

Re: Using %Let in text file

While using a macro name &name1 in a program, I think you need to use the delimiter "." at the end of your macro name which tells SAS, it's the end of the macro name. Like in  &name1._new

Occasional Contributor
Posts: 16

Re: Using %Let in text file

Yeah, I added that but still getting the name not resolved error. 

Solution
‎09-30-2014 12:38 PM
Occasional Contributor
Posts: 16

Re: Using %Let in text file

Ok I think I figured it out.

I had to place the below inside my proc sql statement.  Before it was was sitting outside and most likely not in the same "scope".

filename macro1 "C:\mytext.txt";

%include macro1;

Unless there is a better way of doing it.  Thanks.

Super User
Super User
Posts: 7,392

Re: Using %Let in text file

Well, I think that if you put options mlogic syblogen mprint; on you may see that the thing resolves as something like:

create table mylib.Customers    _new as ...

The macro variable may need %trim'ing.

I have to say though, why create macro variables in an include file? 

Occasional Contributor
Posts: 16

Re: Using %Let in text file

Reason I put macro variables in include file is because I have 5 different SAS files that generate SQL "where" statements.  Instead of going into each SAS file and updating "Where" statements I have one universal Include file which handles variable assignment.  What do you think?

Super User
Super User
Posts: 7,392

Re: Using %Let in text file

Personally I would put them in a SAS dataset and then call them from there.  Really depends on how much information though.

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 301 views
  • 0 likes
  • 3 in conversation