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

I want to use the month and year from today's date and use that as a column in SQL table . 

Below is the code that I am using to get the month and year :

data _null_;
CUR_MONTH =today();
format CUR_MONTH yymmn6.;
put CUR_MONTH;
run;

 

Now , I want to use the variable CUR_MONTH in SELECT statement , something like :

PROC SQL;

SELECT 

&CUR_MONTH , ID , NAME FROM ABC;

 

But , I get Error ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, (, *, +, -, ALL, BTRIM, CALCULATED, CASE, DISTINCT, EXISTS, INPUT, NOT, PUT, SUBSTRING, TRANSLATE,
UNIQUE, USER, ^, ~.

 

 

Can someone please guide . Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10

Try:

data _null_;
    call symputx('CUR_MONTH', put(today(), yymmn6.));
run;

This will initialize CUR_MONTH as a macro variable, which you can use in the subsequent PROC SQL statement.

View solution in original post

2 REPLIES 2
mklangley
Lapis Lazuli | Level 10

Try:

data _null_;
    call symputx('CUR_MONTH', put(today(), yymmn6.));
run;

This will initialize CUR_MONTH as a macro variable, which you can use in the subsequent PROC SQL statement.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 2 replies
  • 1706 views
  • 2 likes
  • 2 in conversation