BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rsadiq1
Calcite | Level 5


      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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1537 views
  • 0 likes
  • 4 in conversation