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.
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.