Proc BranchTo
From sasCommunity
Proc BranchTo allows users to write conditionally executed code based on a logical expression.
Syntax:
Proc BranchTo select = (<logical expression>)
WhenTrue do;
*true statements here;
end;
WhenFalse do;
*false statements here;
end;
otherwise do;
*missing statements here;
end;
Usage:
%Let Libname = sashelp;
%Let Memname = Class;
Proc SQL noprint;
select Nobs
into :Nobs
from Dictionary.Tables
where Libname eq "%upcase(&Libname.)"
and Memname eq "%upcase(&Memname.)"
and Memtype eq 'DATA';
quit;
Proc BranchTo select = &Nobs.
WhenTrue do;
Proc Freq data = &Libname..&Memname.;
end;
WhenFalse do;
%Put Note3: eh?! no data!;
end;
otherwise do;
*missing statements here;
end;
run;
Unfortunately, this does not work. That's because there is no PROC BRANCHTO. The "information" above follows a tradition in the SAS user community of occasionally offering advice which is not intended to be taken seriously. See, for example, Programming for Job Security: Maximize Your Indispensability - Become a Specialist.
PROC BRANCHTO can be emulated, however. One approach is to use the CALL EXECUTE statement in a DATA step. Continuing the example above, the code would be:
data _null_;
select ( abs( sign(&Nobs) ) );
when (1) call execute('Proc Freq data = &Libname..&Memname.; run;');
when (0) call execute('%nrstr(%Put NOTE: eh?! no data! ;) ');
otherwise call execute('%nrstr(%Put NOTE: HOW DID WE GET HERE?;) ');
end;
run;
