please tell me what grammar is wrong.
how to fix it...
i attached a log message below.
%macro number;
%do i=20 %to 21;
proc sql;
create table work.bb_&i. as
select *
from work.dummy
where substr(num_str,5,2) =%nrbquote('&i.');
quit;
%end;
%mend number;
%number;
log message
23 %macro number;
24 %do i=20 %to 21;
25 proc sql;
26 create table work.bb_&i. as
27 select *
28 from work.dummy
29 where substr(num_str,5,2) =%nrbquote('&i.');
30 quit;
31 %end;
32 %mend number;
33 %number;
NOTE: Line generated by the macro function "NRBQUOTE".
1 '20'
-
22
-
200
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, ANY, BTRIM, CALCULATED, CASE, INPUT, PUT, SELECT, SOME, SUBSTRING, TRANSLATE,
USER.
ERROR 200-322: The symbol is not recognized and will be ignored.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.12 seconds
cpu time 0.04 seconds
NOTE: Line generated by the macro function "NRBQUOTE".
1 '21'
-
22
-
200
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, ANY, BTRIM, CALCULATED, CASE, INPUT, PUT, SELECT, SOME, SUBSTRING, TRANSLATE,
USER.
ERROR 200-322: The symbol is not recognized and will be ignored.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.04 seconds
cpu time 0.00 seconds
I am sorry by why are adding macro quotes to a string of digits? There are no macro triggers in that string that would require macro quoting.
where substr(num_str,5,2) ="&i"
I am sorry by why are adding macro quotes to a string of digits? There are no macro triggers in that string that would require macro quoting.
where substr(num_str,5,2) ="&i"
sorry my english..
dummy table is below. (it consist of character like a phone number)
num_str
1 010-2000-0000
2 010-2000-0001
3 010-2000-0002
4 010-2100-0501
5 010-2100-0502
.
.
.
First it would help to describe what you expect this code to do. As in some example data input and results.
Second, to post log entries with errors you really should copy the entire log for the data step or procedure and all the notes and paste them into a code box opened with the forum's </> icon to preserve the formatting. If you read your post you will see that the underscore and 22 have been moved by the forum message window to the left side of the code making the diagnostic _ appear in the wrong place.
Third when debugging macro code it is generally a good idea to set OPTIONS MPRINT; before running the macro code so you get a better view of the code actually generated by the macro.
And I suspect that you don't want or need %nrbquote at all.
where substr(num_str,5,2) ="&i.";
would compare the two extracted characters from NUM_STR to the character value of the macro variable &i. Macro variables won't resolve inside single quotes. You generally have to worry about quoting when you either do not want characters like % or & to be interpreted as the macro processor would use them or if the resolution of the values could be treated as some instruction or keyword.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.