What tiny looking operator packs a mighty punch with large datasets? Your queries are big. Your reports span multiple columns. To top it all you have to summarize data in multiple ways. Are you tempted to throw in the towel? Do you feel like saying a firm “Can’t be done” to your team?
Hint of Advice: DON’T give up! Read on for a handy tip which might well be the most useful tip of 2012.
While mentoring recently on SAS, a banking customer asked, “I source data from several detailed tables. I want this report:"
What if you also need insights on client behavior? You can easily sift through large data with the slick Boolean. Basically the digital computer breaks down everything into Binary, 0s and 1s. Boolean Logic is the heart and core of all programming. It works with simple YES and NO responses. A YES is a value of 1 and a NO is a value of 0. You’ll see how you can create any query combination effortlessly. Once you understand Boolean logic you’ll realize that the best part of it is how surprisingly simple it is!
Without further ado, here’s my code joining data from two tables and summarizing several possible combinations of employee demographics to group report by country.
proc sql; select country, sum(salary < 60000 and employee_gender='M') 'Males and Salary < 60000 ', sum(salary >= 60000 and employee_gender='M') 'Males and Salary >=60000 ', sum(salary < 60000 and employee_gender='F') 'Females and Salary < 60000', sum(salary >= 60000 and employee_gender='F') 'Females and Salary >=60000' from sales as s, orion.employee_addresses as p where s.employee_id=p.employee_id group by country ; quit;
Extend Boolean Logic to any industry data. Below see a report I created using diabetes data where I’m trying to narrow in on high risk individuals, using a combination of bmi (body mass index), age and glucose levels as filters. If you’re curious about the code and data, pop me a note. I’m happy to send it to you. (FYI - this was a great study on diabetes incidence among the Pima Population in Arizona that I presented at a health user group.)
At its very basic, I would break up Boolean logic into two pieces:
It might help to remember that we use Boolean logic almost every day in our daily life. You answer questions with YES or NO responses. Weather check on smartphone apps, calendars help track client appointments. With the help of these YES, or NO type answers we make decisions on what to wear!
To sum up, don’t let the big word BOOLEAN daze you. All I did was take advantage of its capacity to combine multiple conditions for sifting through customer data to get as much intelligence as my heart desires. Wonder why I picked this as my #1 tip? I've used many SAS tips to my advantage. But this one stands out in my mind in its universality of use that I simply had to share with you. Have you used Boolean logic? Do you have a better solution for my customer problem? Write to me. I’d love to hear your experiences.
Shout out to Andrew Macdonald whose question prompted me to write this blog post. And to my colleague Dr. David Yeo with whom I’ve had seemingly endless discussions on Boolean logic.