SAS Conditional programming – If Then
One of the great things about SAS is the use of Macros and conditional programming. The ability to split the code using If - Then processing allows one piece of code to accomplish many things. Here is the basic syntax for If - Then statements in a SAS macro.
%let error1=;
%if %length(&error1) ~=0 %then
%put WARNING: There is an error!;
%else
%put NOTE: There is no error.;
This is the basic example where you want to process one command given a condition. Lets say that you want to process a whole section of code depending on a single condition. See below:
%let error1=;
%if %length(&error1) ~=0 %then %do;
%put WARNING: There is an error!;
<and any other code you want to run here>
%end;
%else
%put NOTE: There is no error.;
<and any other code you want to run here>
%end;
Note that the %do command allows you to run a whole block of code. Be sure to include the %end statement at the end of the code block. Also, the %else portion of both examples are completely optional.