Published on :
Macro NONE

Conditional State WHERE Macro

This code is also available in: Deutsch Español Français
This SAS© script defines a `%where` macro that accepts a single argument, `state`. Inside the macro, the `%superq` function is used to ensure that the `state` value is treated literally, even if it contains special characters or unresolved macros. The macro uses conditional `%if/%else` structures to compare the `state` value to 'NC' (North Carolina) or '%str(OR)' (Oregon). If the state matches 'NC', 'Southeast' is displayed in the SAS© log. If the state matches 'OR', 'Northwest' is displayed. For any other value, 'Unknown' is displayed. The script concludes with a call to the `%where` macro with 'OR' as an argument.
Data Analysis

Type : NONE


The script does not manipulate any data from SAS tables (SASHELP, external, or internally created via DATA STEP/CARDS). It operates solely on literal values and macro parameters, the result of which is written to the SAS log.

1 Code Block
MACRO
Explanation :
This block includes the declaration of the `%where` macro and its subsequent call. The macro is designed to take a `state` argument and, through conditional comparisons using `%superq` for robustness, it displays a corresponding region in the SAS log. The call `%where(OR)` tests the macro's functionality, which should result in 'Northwest' being displayed in the log.
Copied!
1*m203d04d;
2 
3%macro where(state);
4 %IF %superq(state)=NC %THEN %put Southeast;
5 %ELSE %IF %superq(state)=%str(OR) %THEN %put Northwest;
6 %ELSE %put Unknown;
7%mend where;
8 
9%where(OR)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.