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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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