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
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;
Much more information is needed:
&Industry = Tech
You need to use the dot after &VARIABLE. The is no underscore immediately before &VARIABLE.
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;
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.
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!
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.