Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

Using Boolean Values for Variables

You can set a variable to the value of a logical expression. This can make your code much easier to understand and maintain, particularly if the conditions are complex and/or are repeated several times in the code. A simple example:

Program:

data test; 
  set sashelp.tourism; 
  drop _: ; 
  _exchange_rate_condition=exsp > exuk; 
  _price_index_condition=puk > cpisp; 
  if _exchange_rate_condition and _price_index_condition; 
run;

Here we are creating variables called _EXCHANGE_RATE_CONDITION and _PRICE_INDEX_CONDITION that are either true (1) or false (0) depending on the result of the condition that follows (and which we can usually drop from the output dataset).

Similarly you could make definitions like:

_teenage_boy=12

Use of "_" is simply a convention that makes it easy to drop all temporary variables on a DROP statement (as in this example).

A favourite trivia question: Is this SAS statement valid, and if so, what does it mean?

            a=b=c=d;

Answer: Yes, it's perfectly valid. It sets A to 1 ('true’) if the values of B, C and D are all the same, otherwise it sets A to 0.

Only a is a Boolean here and the statement could more clearly be written:

a=(b=c=d);