BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tegg
Calcite | Level 5

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!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

Tegg
Calcite | Level 5

Hey KurtBremser,

 

that works. Thank you very much for your reply!

 

 

Tegg
Calcite | Level 5

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!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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