LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (April 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 5 Apr 2005 09:22:16 -0400
Reply-To:     "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:      Templates, regular expressions, resolutions and callbacks
Comments: cc: suggest@sas.com
Content-Type: text/plain; charset="iso-8859-1"

I have some template html I want to process through a data step.

filename template temp; data _null_; file template; input; put _infile_; datalines4; <html> <head> <title><macro>&title</macro></title> </head> <body> <h1><macro>&foo</macro> and <macro>&bar</macro></h1> <p>An ampersand looks like this: &amp;</p> </body> </html> ;;;;

In the template, anything within <macro>...</macro> is to be resolved by the macro system and replaced into the template. The fake tags are used because normal html can have lots of & and % that should not be damaged by blindly using RESOLVE.

So, I need a data step that reads the template and does the replacement as needed. *if* SAS had replacement with *callback* (in the manner of PHP's preg_replace_callback) everything could be done neatly as follows:

%let title = This is my Title; %let foo = Cats; %let bar = Dogs;

filename resolved temp;

data _null_; infile template; file resolved;

if _n_ = 1 then rx = prxParse ('s:<macro>(.*?)</macro>:`resolve($1)`:io');

retain rx;

input; if prxMatch (rx, _infile_) then do; call prxChange (rx,-1,_infile_); putlog _infile_; end;

put _infile_; run;

What is callback? Look at the replacement text carefully, it contains backticks (also known as grave). If a replace contains backticks, the system would presume that which is enclosed in a function call that has to be made, whose results are used as the replacement text.

A look at the log shows ------ <title>`resolve(&title)`</title> <h1>`resolve(&foo)` and `resolve(&bar)`</h1> ------

So, alas, SAS prx* definitely does not (and may never) support callbacks. Callbacks would be a great benefit it they were ever added to the prx* repertoire. [call prxChangeWithCallback]

Any ideas on how to replace (possibly multiple times) the <macro> tag and its encapsulated expression, with the expression's resolution per the macro system?

Richard A. DeVenezia


Back to: Top of message | Previous page | Main SAS-L page