BookmarkSubscribeRSS Feed
nelsonsch
Calcite | Level 5

Hi all,

 

I'm essentially trying to use a boolean to create a calculated variable to do the following:

 

IF ( {a = 0} AND {b >0} )
RETURN 'NA'
ELSE c

 

Where a, b, and c are aggregated measures.

 

Anyone have any experience getting around "Type Mismatch" for something like this?

 

Thanks!

1 REPLY 1
ballardw
Super User

SAS allows one type of data per variable: numeric or character. So you can't "mismatch" the data.

It really isn't clear though I am going to assume that C is a numeric variable. You can get SAS to  display text like 'NA' using a format associated with a specific value. From context I would use a "special missing" which are values like .A .B … .Z or ._

The use a format to display the text NA as desired for that value.

 

proc format libray=work;
value MyNA
.N = 'NA'
;
run;

data junk;
  x=.N ;
  format x MyNA.;
run;

proc print data=junk;
run;

This avoids attempting to assign text to what looks like it really should be numeric.

 

Or you could just use the generic missing value of . instead of the ".N" without any special format. The missing value would not be used in most calculations (it is less than any value though) and you would likely know that missing values come from this sort of assignment.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1432 views
  • 2 likes
  • 2 in conversation