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

Hi. I have two WHEN statements within my Case statement and I'm attempting to enclose part of the When statement in parentheses using SAS contatentation bars, but I'm getting syntax errors:

 

		proc sql;
		create table QueryData&ZIP5._&RULE_ORDER_CHAR as
		select DISTINCT %unquote(%str(%')&ANALYSIS_DESC.%str(%')) as rule_nm length = 58, 
					a.actual_dlvry_date as ad_dt, 
					a.imb_code length = 31, 
					&RULE_ORDER as rule_order,
					a.imb_dlvry_zip_5,
					CASE 
						WHEN "("||%scan(&rule_list, 1,#)||")" AND a.RULEFLAG = "-" THEN "&RULE_ORDER"
						WHEN "("||%scan(&rule_list, 2,#)||")" AND a.RULEFLAG = "-" THEN "&RULE_ORDER"
					END as RuleFlag
		from QueryData&ZIP5 as a 
		inner join QueryData&ZIP5 as b 
		on a.imb_code=b.imb_code 
		where a.source="A" and b.source="B" 
220                       &RULE_ORDER as rule_order,                     a.imb_dlvry_zip_5,                     CASE
220!               WHEN "("||%scan(&rule_list, 1,#)||")" AND a.RULEFLAG = "-" THEN "&RULE_ORDER"                         WHEN
                                                   --
                                                   22
                                                   76
220! "("||%scan
ERROR 22-322: Syntax error, expecting one of the following: !, &, AND, OR, THEN, |.

ERROR 76-322: Syntax error, statement will be ignored.

Can anyone help me to resolve this error?

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

There is no need to do concatenation.

You may write:

    CASE WHEN (%scan(&rule_list, 1,#)) and ...

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

There is no need to do concatenation.

You may write:

    CASE WHEN (%scan(&rule_list, 1,#)) and ...

buechler66
Barite | Level 11
Thanks for your insight!
Reeza
Super User

I'm not sure I see the need for macro code at all:

 

WHEN (scan("&rule_list", 1, "#") AND a.RULEFLAG = "-" THEN "&RULE_ORDER"

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 858 views
  • 2 likes
  • 3 in conversation