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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1263 views
  • 3 likes
  • 4 in conversation