DATA Step, Macro, Functions and more

CASE within a CASE

Reply
Contributor
Posts: 35

CASE within a CASE

Here is the code....

 

CASE WHEN BD.VIN = S.VIN THEN S.Dlr_GMF_ID ELSE "" END AS SOLD_DEALER_CODE_Cognos,

 

CASE WHEN BD.BIDDER_DEALER_CODE = (CASE WHEN BD.VIN = S.VIN THEN S.Dlr_GMF_ID ELSE "" END AS SOLD_DEALER_CODE_Cognos) THEN "WON" ELSE "LOST" END AS WON_LOSS

 

What am I doing wrong here?

Super User
Posts: 17,737

Re: CASE within a CASE

Try removing as cognos_... variable portion of your nested CASE portion.

 

Another possible option within the statement may be IFC

Respected Advisor
Posts: 3,886

Re: CASE within a CASE

Not tested but I believe both case statements below would give you what you're after

  CASE 
    WHEN BD.BIDDER_DEALER_CODE = 
      (CASE 
        WHEN BD.VIN = S.VIN THEN S.Dlr_GMF_ID 
        ELSE "" 
        END 
      ) 
      THEN "WON" 
    ELSE "LOST" 
    END 
    AS WON_LOSS

  CASE 
    WHEN BD.VIN = S.VIN and BD.BIDDER_DEALER_CODE = S.Dlr_GMF_ID then "WON"
    when BD.VIN ne S.VIN and BD.BIDDER_DEALER_CODE=' ' then "WON"
    ELSE "LOST" 
    END 
    AS WON_LOSS
Respected Advisor
Posts: 4,640

Re: CASE within a CASE

Should be

 

CASE 
	WHEN BD.VIN = S.VIN THEN S.Dlr_GMF_ID 
	ELSE "" 
        END AS SOLD_DEALER_CODE_Cognos,
CASE 
	WHEN BD.BIDDER_DEALER_CODE = CALCULATED SOLD_DEALER_CODE_Cognos THEN "WON" 
	ELSE "LOST" 
        END AS WON_LOSS
PG
Ask a Question
Discussion stats
  • 3 replies
  • 149 views
  • 0 likes
  • 4 in conversation