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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 727 views
  • 0 likes
  • 2 in conversation