Hi Guys,
I'm trying to creating the monthly table
something like work. test_052019
used code
data test_&mnth&yr;
set test_Add;
run;
But getting below error
22
__
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.
ERROR 200-322: The symbol is not recognized and will be ignored.
Used below code for macro
Month is $2
Proc sql noprint ;
select distinct Month into : Month
from Input;
quit;
%let mnth = %qtrim(&Month);
%put &mnth
Year is numeric
Proc sql noprint ;
select distinct Year into : Year
from Input;
quit;
%let yr = %qtrim(&Year);
%put &yr ;
Any help, please
Something like this?
data _null_;
call symputx('mnth', put(month(today()), z2.));
call symputx('yr', year(today()));
run;
%put &mnth. &yr.;
data test_&mnth.&yr.;
a=1;
run;
Please post the whole log of the failing step.
Use the {i} button for posting the log, so that the horizontal positions and all conent are kept unchanged.
The ERROR message alone, without the corresponding code, is mostly useless.
Several items stand out about your post.
Why are you using %QTRIM? If you want to eliminate leading and trailing blanks, you can use simply:
%let mnth = &month;
%let yr = &year;
Adding quoting characters can only cause trouble in this case.
Secondly, you would be better off creating test_201905 instead of test_052019. That way, when you have created a series of data sets that span multiple years, the data set names will alphabetize in order.
Third, you should be using this statement if you are trying to debug the code:
options mprint;
That way, you can see the SAS code generated by any macros you execute.
Finally, have you examined your macro variables? SELECT DISTINCT can be extracting more than one distinct value. Are you sure that the values you are extracting are the correct ones?
Why are you putting spaces into to your macro variables if you don't want them?
proc sql noprint ;
select Month,Year
into :Mnth trimmed
, :Yr trimmed
from Input
;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.