Exploring, modeling, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

Using IF statements in Query Builder

Occasional Contributor
Posts: 11

Using IF statements in Query Builder

The query builder allows the creation of custom expressions that use basic arithmetic.

However, it seems that it is impossible to use any sort of Boolean Logic statements (VA 6.4)

This is really, really annoying and value and purpose of the Query Building feature.

Please advise whether this has been resolved in later versions.

Super User
Posts: 1,209

Re: Using IF statements in Query Builder


Sorry to hear of your frustrations. The SAS Visual Analytics Query Builder generates SQL code and as such if statements are not supported with this ANSI standard. If you are wanting to do Boolean logic, have a look at the CASE statement that can be used in a column expression, http://support.sas.com/documentation/cdl/en/vaug/67270/HTML/default/viewer.htm#n0bk4cm9klgbh3n1jxpb8...

Kind Regards,


Occasional Contributor
Posts: 11

Re: Using IF statements in Query Builder

Hi Michelle,

Yes, a CASE statement would work well. However, I cannot find any example of how to use the statement in any of the documentation for VA, and the link that you send through does not help (aside from "Enter arithmetic operators and expressions such as CASE statements directly in the SQL expression area").

But please explain why the functionality within the Query tool in terms of expression building screens is so deficient???

VA is promoted as a tool that requires no knowledge of SQL, and while the expression builders within VA Explorer/Reporter are great - the functionality of the Query tool is woefully deficient.

The documentation I could find on the CASE syntax was here: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473682.htm

I could not find anything related to CASE and VA specifcally.


SAS Employee
Posts: 23

Re: Using IF statements in Query Builder

Hi James, thank you for your feedback and sorry to hear of your frustration. We agree it makes sense to add additional functions and UI for this kind of logic. In the meantime CASE and other expressions from the doc or copied from your exploration or report expressions can be typed or pasted into the Data Builder expression area. A simple example is shown in the screenshot below. We will also pass along your feedback to our documentation team.


Thanks again,


Occasional Contributor
Posts: 11

Re: Using IF statements in Query Builder

Thanks for that I-Kong,

I have had some success with it now - which has been handy.

I have discovered some bad performance issues if you try to create calculated items on 165million rows of data, so I had to do some of the initial logic in Query Builder to filter out the data and perform the basic logic.

Thanks for passing this do the documentation team, the Query builder is definately not well covered compared to Explorer and Reporter.


New Contributor
Posts: 2

Re: Using IF statements in Query Builder

[ Edited ]

What if the lookups is too big and changable , then i cant make it constant condition,


for example the CASEMGMT.REF_TABLE_VALUE contains parents and childs lookups like attached image , then how to select the description automatically ? 

value desc.png


It's hard to code it to case X_RT_ECONOMIC_CD ="4_203" then 'some text description here'


Can i write innser select inside VA expression like below :

define X_KYC_ECONOMIC_CODE='2_0';

Post a Question
Discussion Stats
  • 5 replies
  • 1 like
  • 4 in conversation