DATA Step, Macro, Functions and more

how do i resolve macro variable inside names in external file

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

how do i resolve macro variable inside names in external file

Hello everybody,

 

I have a external file as a txt. file. Inside the file there is a proc SQL Statement.

My Textfile looks like:

 

proc SQL;

select * from afdeb.dbdb01eg;
quit;

 

 

Now I want to replace the 01 inside the table name as a macro variable like afdeb.dbdb&_xx.eg.

I know if I want to replace macro variables in external files I have to work with double quotes like afdeb.dbdb"&_xx."eg. But it only works outside a name.

For your understanding: I have tables with generations. 01 is the current month, 02 the month before and so on. My plan is to increment the generations to get all data. The SQL Statement lays on a Server in a text file.  

Is it possible to resolve a macro variable in a external file inside a name?

 

Many thanks for your help!

 

 

 


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 10,280

Re: how do i resolve macro variable inside names in external file

If you define a macro variable first, you can use it in an include:

/* first, let's create the textfile with SAS code */

filename external temp;

data _null_;
file external;
input textline $80.;
put textline;
datalines4;
proc SQL;
create table test as select * from sashelp.c&mac.s;
quit;
;;;;
run;

/* now call it, and set the macro variable before */

%let mac=las;
options source2; /* let's see the code we get */
%include external;

In your case, replace the temporary file reference with your actual filename, and since you already have it, the data _null_ step is of course not necessary. It's just there to create an external file for testing from code.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
2 weeks ago
Super User
Posts: 10,280

Re: how do i resolve macro variable inside names in external file

If you define a macro variable first, you can use it in an include:

/* first, let's create the textfile with SAS code */

filename external temp;

data _null_;
file external;
input textline $80.;
put textline;
datalines4;
proc SQL;
create table test as select * from sashelp.c&mac.s;
quit;
;;;;
run;

/* now call it, and set the macro variable before */

%let mac=las;
options source2; /* let's see the code we get */
%include external;

In your case, replace the temporary file reference with your actual filename, and since you already have it, the data _null_ step is of course not necessary. It's just there to create an external file for testing from code.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 3

Re: how do i resolve macro variable inside names in external file

Posted in reply to KurtBremser

Hey KurtBremser,

 

that works. Thank you very much for your reply!

 

 

New Contributor
Posts: 3

Re: how do i resolve macro variable inside names in external file

Posted in reply to KurtBremser

Hey KurtBremser,

 

I have another questions regarding the testfiles in sas.

I want to create two tables. If the table name contains 01 I want to create the first tabe, if 02 another.

Is it possible to put the if-condition into the Textfile or do i have to do it in a separate macro?

 

Regards!

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 63 views
  • 0 likes
  • 2 in conversation