BookmarkSubscribeRSS Feed
jeffbezos
Calcite | Level 5

Hi, I've assigned two values using %let and wish to use them to select the column 201809 from my table rather than create the value '201809' in my proc sql statement.  Here's the code i have so far: 

 

%let billyr = 2018;
%let billmth = 09;

 

proc sql;

create table test as select prod_cd, &billyr.&billmth. from sometable;

quit;

 

Any help would be greatly appreciated.

 

Thanks in advance,

Jeff!

3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
In SAS tables, a column name has to start with a letter or underscore. You cannot have a variable named '201809' if "sometable" is a SAS dataset. Can you show the PROC CONTENTS for WORK.SOMETABLE which shows the EXACT column name that you are trying to build with macro variables?

Cynthia
jeffbezos
Calcite | Level 5

Thank you, modified my code to add a character in front of the variable helped fix it.  noob move.


@Cynthia_sas wrote:
Hi:
In SAS tables, a column name has to start with a letter or underscore. You cannot have a variable named '201809' if "sometable" is a SAS dataset. Can you show the PROC CONTENTS for WORK.SOMETABLE which shows the EXACT column name that you are trying to build with macro variables?

Cynthia

 

Tom
Super User Tom
Super User

If you somehow managed to create a variable name that starts with a number then you need use a name literal to reference it.

%let billyr = 2018;
%let billmth = 09;

proc sql;
create table test as
 select prod_cd, "&billyr.&billmth."n as usable_varname
 from sometable
;
quit;

You also need to make sure that VALIDVARNAME option is set to ANY.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 585 views
  • 0 likes
  • 3 in conversation