DATA Step, Macro, Functions and more

Recoding a variable - Not sure I'm using Case correctly

Accepted Solution Solved
Reply
Regular Contributor
Posts: 212
Accepted Solution

Recoding a variable - Not sure I'm using Case correctly

[ Edited ]

I'm trying to recode RuleFlag to the value of '1' (&Rule_Order_Char) when the following conditions are met:  

 

A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL or A.ACTUAL_DLVRY_DATE > B.ACTUAL_DLVRY_DATE AND a.RULEFLAG = "-"

 

But I'm getting the error:  

 

ERROR: Operand of WHEN clause 1 is not the same data type as the CASE operand.

 

Am I using Case the wrong way? Is there another way to achieve the desired recoding during a Select statement? ny help would be much appreciated.

 

2224          proc sql;
2225          create table QueryData&ZIP5._&RULE_ORDER_CHAR as
SYMBOLGEN:  Macro variable ZIP5 resolves to 00926
SYMBOLGEN:  Macro variable RULE_ORDER_CHAR resolves to 1
2226          select DISTINCT %unquote(%str(%')&ANALYSIS_DESC.%str(%')) as rule_nm length = 58,
SYMBOLGEN:  Macro variable ANALYSIS_DESC resolves to TEST
2227                      a.actual_dlvry_date as ad_dt,
2228                      a.imb_code length = 31,
2229                      &RULE_ORDER as rule_order,
SYMBOLGEN:  Macro variable RULE_ORDER resolves to 1
2230                      a.imb_dlvry_zip_5,
2231                      CASE a.RULEFLAG
2232                          WHEN A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL or
            A.ACTUAL_DLVRY_DATE > B.ACTUAL_DLVRY_DATE
 AND a.RULEFLAG = "-" THEN "&RULE_ORDER_CHAR"
SYMBOLGEN:  Macro variable RULE_ORDER_CHAR resolves to 1
2233                      END as rule_flag
2234          from QueryData&ZIP5 as a
SYMBOLGEN:  Macro variable ZIP5 resolves to 00926
2235          inner join QueryData&ZIP5 as b
SYMBOLGEN:  Macro variable ZIP5 resolves to 00926
2236          on a.imb_code=b.imb_code
2237          where a.source="A" and b.source="B";
ERROR: Operand of WHEN clause 1 is not the same data type as the CASE operand.
NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will result in a missing value for the
      CASE expression.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
2238          quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):

 


Accepted Solutions
Solution
‎08-16-2016 07:27 PM
Super User
Posts: 19,789

Re: Recoding a variable - Not sure I'm using Case correctly

Posted in reply to buechler66

Remove the a.ruleflag after the word Case. 

 

 

View solution in original post


All Replies
Solution
‎08-16-2016 07:27 PM
Super User
Posts: 19,789

Re: Recoding a variable - Not sure I'm using Case correctly

Posted in reply to buechler66

Remove the a.ruleflag after the word Case. 

 

 

Regular Contributor
Posts: 212

Re: Recoding a variable - Not sure I'm using Case correctly

Posted in reply to buechler66
Worked. Thanks for your time!
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 239 views
  • 1 like
  • 2 in conversation