![]() Chapter Contents |
![]() Previous |
![]() Next |
| %DO %WHILE |
| Type: | Macro statement |
| Restriction: | Allowed in macro definitions only |
| See also: | %END |
| Syntax | |
| Details | |
| Example | |
| Removing Markup Tags from a Title | |
Syntax |
|
%DO %WHILE
(expression);
text and macro program statements |
| %END; |
These examples illustrate expressions for the %DO %WHILE statement:
| Details |
The %DO %WHILE statement tests the condition at the top of the loop. If the condition is false the first time the macro processor tests it, the %DO %WHILE loop does not iterate.
| Example |
This example demonstrates using the %DO %WHILE to strip markup (SGML) tags from text to create a TITLE statement:
%macro untag(title);
%let stbk=%str(<);
%let etbk=%str(>);
/* Do loop while tags exist */
%do %while (%index(&title,&stbk)>0) ;
%let pretag=;
%let posttag=;
%let pos_et=%index(&title,&etbk);
%let len_ti=%length(&title);
/* Is < first character? */
%if (%qsubstr(&title,1,1)=&stbk) %then %do;
%if (&pos_et ne &len_ti) %then
%let posttag=%qsubstr(&title,&pos_et+1);
%end;
%else %do;
%let pretag=%qsubstr(&title,1,(%index(&title,&stbk)-1));
/* More characters beyond end of tag (>) ? */
%if (&pos_et ne &len_ti) %then
%let posttag=%qsubstr(&title,&pos_et+1);
%end;
/* Build title with text before and after tag */
%let title=&pretag&posttag;
%end;
title "&title";
%mend untag;
You can invoke the macro UNTAG as
%untag(<title>Total <emph>Overdue </emph>Accounts</title>)
The macro then generates this TITLE statement:
TITLE "Total Overdue Accounts";If the title text contained special characters such as commas, you could invoke it with the %NRSTR function.
%untag( %nrstr(<title>Accounts: Baltimore, Chicago, and Los Angeles</title>))
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.