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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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