Desktop productivity for business analysts and programmers

syntax error

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

syntax error


      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;


Accepted Solutions
Solution
Monday
Respected Advisor
Posts: 4,757

Re: syntax error

[ Edited ]

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


All Replies
Esteemed Advisor
Posts: 6,275

Re: syntax error

It's probably caused by &mbr_id_count being zero.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
Monday
Respected Advisor
Posts: 4,757

Re: syntax error

[ Edited ]

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.

Highlighted
Esteemed Advisor
Esteemed Advisor
Posts: 6,983

Re: syntax error

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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