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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 2 replies
  • 961 views
  • 2 likes
  • 2 in conversation