Case statement with different data types creating same variable

Reply
Contributor
Posts: 31

Case statement with different data types creating same variable

Hi ,

i have a data where when C.xxy = AQD, PPY,GGA then i need to use substr , input function and  insert new value respectively

 

 

when C.xyy ='AQD' and B.nm = 'PART' then substr(cc,1,3)
when C.xyy =  'PPY'    and B.nm =  'ITEM' then input(scan(cc,1),2.)
when C.xyy = 'GGA'   and B.nm  ='SALE' then 'Insurance'

else '' end as v1

 

Can anyone pls help on how to approach with this kind of problem

 

 

But i get and error saying

ERROR: Result of WHEN clause 1 is not the same data type as the preceding results.
ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.

 

and also

 

ERROR: Result of WHEN clause 1 is not the same data type as the preceding results.
ERROR: Result of WHEN clause 3  is not the same data type as the preceding results.

Super User
Posts: 17,828

Re: Case statement with different data types creating same variable

Remove the input function for the second case. If you need the input something you can apply a PUT around it as well. 

 

The error is correct, you can't have character and numeric types in the same column. 

 

Contributor
Posts: 31

Re: Case statement with different data types creating same variable

Yes,

but i am using input so that it removes leading zeros and now the character column is converted to numeric

Super User
Posts: 17,828

Re: Case statement with different data types creating same variable

Then wrap it in a PUT

 

PUT(INPUT(SUBSTR(..., , ), 2.), $2.)

Contributor
Posts: 31

Re: Case statement with different data types creating same variable

[ Edited ]

Its not working

 

when i used

when C.xyy ='AQD' and B.nm = 'PART' then substr(cc,1,3)
when C.xyy =  'PPY'    and B.nm =  'ITEM' then put(input(scan(cc,1),2.),$2.)

 

it says

 

ERROR: Character format $ in PUT function requires a character argument.
ERROR: Result of WHEN clause 1 is not the same data type as the preceding results.
ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.

 

 

Super User
Posts: 9,681

Re: Case statement with different data types creating same variable

Or don't use input() ;

input(scan(cc,1),2.)
-->
scan(cc,1)

Super User
Posts: 17,828

Re: Case statement with different data types creating same variable

I probably have the format wrong for the put statement, try 2.

Ask a Question
Discussion stats
  • 6 replies
  • 521 views
  • 3 likes
  • 3 in conversation