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-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!

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