Hello, I can not seem to find the syntax error in this code, it seems broad but maybe I am missing something
thanks
NOTE: Line generated by the invoked macro "WHERE_MACRO_CS_KEY_CLAUSE".
1355 )
_
22
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
a datetime constant, a missing value.
%macro where_macro_cs_key_clause;
%IF &mbr_id_count=1 %THEN %DO;
mbr_id IN (&mbr_id_1)
%END;
%ELSE %DO;
mbr_id IN (
%DO i = 1 %TO &mbr_id_count;
&&mbr_id_&i %IF &i ^= &mbr_id_count %THEN ,;
%END;
)
%END;
%MEND where_macro_cs_key_clause;
I think Kurt's answer is correct. Also note that you don't need the top section of your logic. The bottom section covers that case. For example, this still works when &MBR_ID_COUNT is 1:
%macro where_macro_cs_key_clause;
%local i;
%IF &mbr_id_count >= 1 %THEN %DO;
mbr_id IN (
%DO i = 1 %TO &mbr_id_count;
&&mbr_id_&i %IF &i ^= &mbr_id_count %THEN ,;
%END;
)
%END;
%MEND where_macro_cs_key_clause;
Edited: Here's a secondary guess as to what the problem could be.
If these macro variables are created by user answers to prompts, it's possible that when there is only one value entered by the user the name of the macro variable should be &MBR_ID and not &MBR_ID_1. That would mean changing the top portion of the logic very slightly.
It's probably caused by &mbr_id_count being zero.
I think Kurt's answer is correct. Also note that you don't need the top section of your logic. The bottom section covers that case. For example, this still works when &MBR_ID_COUNT is 1:
%macro where_macro_cs_key_clause;
%local i;
%IF &mbr_id_count >= 1 %THEN %DO;
mbr_id IN (
%DO i = 1 %TO &mbr_id_count;
&&mbr_id_&i %IF &i ^= &mbr_id_count %THEN ,;
%END;
)
%END;
%MEND where_macro_cs_key_clause;
Edited: Here's a secondary guess as to what the problem could be.
If these macro variables are created by user answers to prompts, it's possible that when there is only one value entered by the user the name of the macro variable should be &MBR_ID and not &MBR_ID_1. That would mean changing the top portion of the logic very slightly.
Sorry, that just seems a mess to me. Why not put your where clause items in a dataset (called list_ds in the below) and then do:
where mbr_id in (select mbr_id from list_ds);
Far simpler than messing around with macro lists, and macro loops and all that.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.