SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Stepik
Obsidian | Level 7

Dear team,

 

Column 1 consists of numeric values and also missing ones assigned just with one dot '.'.

I would like to create a new column with the outcome depending if Column1 numeric or '.'.

Below is the simplified code using PROC SQL:

 

case
when Column1 = '.'
then 3
else 4 
end

 

The next error appears "ERROR: Expression using equals (=) has components that are of different data types.".

I also tried to use IFN function, IFN (Column1 = '.', 3, 4) It gives the same ERROR.

 

Can someone assist please?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
. is SAS notation for missing for numeric. So all values are numeric.

This should work:

case when missing(column1) then 3 else 4 end

View solution in original post

4 REPLIES 4
Reeza
Super User
. is SAS notation for missing for numeric. So all values are numeric.

This should work:

case when missing(column1) then 3 else 4 end
Tom
Super User Tom
Super User

So the error message is say that the comparison operator

Column1 = '.'

is trying to compare values of different TYPEs.  SAS only has two types.  Floating point numbers and fixed length character strings.   Since the right side is clearly a character constant then COLUMN1 must be a NUMERIC variable.  So you need to compare it to a numeric value.

Column1 = .

Which will test if column1 has normal missing value.

If you want to test if COLUMN1 has other missing values, such as .A or .Z, then you could use the MISSING() function instead of the comparison operator.

missing(Column1)

Note that the MISSING() function will also work if COLUMN1 is character.  SAS will treat a character value that only contains spaces as missing.

Stepik
Obsidian | Level 7
Tom, what would be the solution if I would like to use IFN (IFC) function?
PaigeMiller
Diamond | Level 26

Same as has been discussed above, you use column1=. instead of column1='.'

--
Paige Miller

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 4 replies
  • 737 views
  • 3 likes
  • 4 in conversation