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-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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