BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?
2 REPLIES 2
prholland
Fluorite | Level 6
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
deleted_user
Not applicable
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1238 views
  • 0 likes
  • 2 in conversation