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

Howdy,

 

I am trying to use a variable in the middle of a table name.  Is this doable?  I am assuming yes.  Can someone help me with the correct syntax?  I tried it with/without the period and I get an error.

 

Thanks

 

Jeff

 

CREATE TABLE WORK.&Industry._01 AS 
1 ACCEPTED SOLUTION

Accepted Solutions
sustagens
Pyrite | Level 9

If you are just creating the table in the temporary WORK library, try removing "WORK." you can do away without specifying it in front of your table name.

 

There needs to be a period after the &variable_name. because there is a suffix after it.

It may also be worthwhile checking the line where Industry is assigned a value.

 

All of the following variations work:

%let Industry=Tech;
%put &=Industry;

proc sql;
/*create table WORK._&Industry._01 as */ /*create table _&Industry._01 as */
/*create table WORK.&Industry._01 as */ /*create table &Industry._01 as */
select * from sashelp.cars; quit;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Much more information is needed:

 

  1. What is the value of &industry?
  2. What is the exact word-for-word error message?
  3. Can you send me some bacon?
 
--
Paige Miller
JeffM1968
Fluorite | Level 6

&Industry = Tech

 

JeffM1968_0-1588551341115.png

 

PaigeMiller
Diamond | Level 26

You need to use the dot after &VARIABLE. The is no underscore immediately before &VARIABLE.

 
 
--
Paige Miller
sustagens
Pyrite | Level 9

If you are just creating the table in the temporary WORK library, try removing "WORK." you can do away without specifying it in front of your table name.

 

There needs to be a period after the &variable_name. because there is a suffix after it.

It may also be worthwhile checking the line where Industry is assigned a value.

 

All of the following variations work:

%let Industry=Tech;
%put &=Industry;

proc sql;
/*create table WORK._&Industry._01 as */ /*create table _&Industry._01 as */
/*create table WORK.&Industry._01 as */ /*create table &Industry._01 as */
select * from sashelp.cars; quit;
JeffM1968
Fluorite | Level 6
All of these tidbits did the trick.

Thanks!!
Reeza
Super User

Check how your macro variable is being created and resolved. You may have some spaces after it causing it to resolve as:

 

 WORK.TECH      _01 AS 

You can check by using the appropriate debugging options and seeing this in your log:

options mprint symbolgen;

If this is the case, you can fix it by using CALL SYMPUTX() (note the X) or TRIMMED option if you're creating the macro variable via SQL which will remove the trailing spaces. 

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1112 views
  • 3 likes
  • 4 in conversation