BookmarkSubscribeRSS Feed
meckarthik
Quartz | Level 8

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

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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;
Kurt_Bremser
Super User

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.

Astounding
PROC Star

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?

Tom
Super User Tom
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 949 views
  • 4 likes
  • 5 in conversation