As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Macro code for Case or Select

From sasCommunity
Jump to: navigation, search

This is a SAS-ware Ballot Item created on Mar 11, 2015 12:19 PM

Macro Statement: %SELECT or %CASE

Add a statement to Macro Language for functionality similar to SELECT statement in Data Step or CASE statement in SQL


For Example

%macro foo;   
%local foo; 
%let foo=abc;   
   %when(XYZ) %put >>>blah; 
   %otherwise %put >>>nope; 

This is easy to code and readable, too.

Branch Value is Text

%macro go_to(label=abc);
%goto &label;
   %put actions for &=label;
   %goto exit;
   %put actions for &=label;
   %goto exit;
   %put actions for &=label;
   %goto exit;

Branch Value is False or True (not False)

%macro go_to(value=x,testing=1);
%let testing = %eval(0 ne &testing);
%let branch  = %eval(0 ne &value);
%goto _&branch;
   %put actions for false &=value &=branch;
   %goto exit;
   %put actions for true &=value &=branch;
   %goto exit;

--Ronald_J._Fehd macro.maven == the radical programmer (talk) 14:42, 26 May 2015 (CDT)