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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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