Desktop productivity for business analysts and programmers

How to create a mixed-data-type variable in EG Query?

Reply
N/A
Posts: 0

How to create a mixed-data-type variable in EG Query?

I am trying to replicate the following SAS codes using the EG query:

If "Var01"n = 0 then "Var02"n = "abcdefg";
else "Var02"n = "Var01"n/100;

The codes run without any problem in EG. The EG won't allow the following in the query:

Case When Var01=0 then 'abcdef' Else Var01/100 End

since "Result of WHEN clause 2 is not the same data type as the preceding results". I tried to convert the numeric value to string but did not success.

Any suggestions?
Frequent Contributor
Posts: 81

Re: How to create a mixed-data-type variable in EG Query?

Have you tried converting the numeric result using a PUT() function in the THEN clause? You may need to change the BEST. format to suit your data values:

Case When "Var01"n=0 then 'abcdef' Else PUT("Var01"n/100, BEST.) End

Data step code statements are probably too relaxed, and will auto-convert numeric and character values, as necessary. SQL statements are not as relaxed, and require character variables to be given character values, and numeric variables to be given numeric values.

.......Phil Holland
N/A
Posts: 0

Re: How to create a mixed-data-type variable in EG Query?

Phil,

I was trying Put( ) function yesterday but did not use BEST. format. I just tried the BEST. format and it worked. Thanks a lot.

Yimin
Ask a Question
Discussion stats
  • 2 replies
  • 98 views
  • 0 likes
  • 2 in conversation