Date: Wed, 11 May 2005 01:35:41 +0000
Reply-To: iw1junk@COMCAST.NET
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <iw1junk@COMCAST.NET>
Subject: Re: Embedding code that contains % via %include
Nigel,
The %LET statement would have worked fine without the %STR() because no
symbols needed hiding, in fact, %STR() alone could not hide any of the
symbols in your assignment.
The reason you had trouble was that you were writing an old style macro, a
language which should have died 23 years ago. It cannot handle %-signs and
has no quoting ability.
In trying to understand what was happening, I ended up with the following
simplification.
NOTE: SAS initialization used:
real time 0.28 seconds
cpu time 0.22 seconds
1 MACRO _mycode
2 'ABC%
3
4 data _null_ ;
5 x = 1 ;
6 put x= ;
7 run ;
x=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
8
9 %put begin
10 _mycode
11 end
12 ;
begin 'ABC end ;
NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
real time 0.29 seconds
cpu time 0.23 seconds
Note that the single quote mark was accepted and that your internal %-sign
ended the old style macro. The DATA step executed in a reasonable fashion
and the %PUT statement executed. There is only one little semi-colon at
the end of written line that I cannot explain, but that I believe is caused
by some strange interaction between the two macro languages.
There is nothing that can be done with an old style macro that cannot be
done with a %LET statement and macro variable reference. I suggest that
you stop writing old style macros and convert any that you already have in
past programs.
Ian Whitlock
=================
Date: Tue, 10 May 2005 15:23:57 +0100
Reply-To: "Greenwood, Nigel EDS-DWP" <nigel.greenwood1@EDS.DWP.GSI.GOV.UK>
Sender: "SAS(r) Discussion"
From: "Greenwood, Nigel EDS-DWP"
<nigel.greenwood1@EDS.DWP.GSI.GOV.UK>
Subject: Re: Embedding code that contains % via %include
Content-Type: text/plain; charset="iso-8859-1"
Harry,
Thanks for the link - I spotted this thread earlier today but that was
before I had the problem so didn't think it relevant to today's challenges.
It's less complex than my requirement but the thread starter's code may
also
be more complex BUT it does the job for me!
I used a %let statement & %STR() combination to assign the partial case
statement string and substituted that in the inline code which worked.
This
has some similarities with Ian's sample.
Thanks,
Nigel
-----Original Message-----
From: Harry Droogendyk [mailto:harry.droogendyk@RBC.COM]
Sent: 10 May 2005 14:51
To: SAS-L
Subject: Re: Embedding code that contains % via %include
See Ian's idea for a similar situation:
http://listserv.uga.edu/cgi-bin/wa?A2=ind0505b&L=sas-l&F=&S=&P=11681
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L]On Behalf Of
Greenwood, Nigel EDS-DWP
Sent: Tuesday, May 10, 2005 9:33 AM
To: SAS-L
Subject: Embedding code that contains % via %include
Hi List,
(OS: z/OS V1.4 SAS V8.2)
I have a (not large) piece of PROC SQL code which I would like to
customise at run time based on some environmental specific code. I have 4
of
these environments and YES it would be quite easy to clone the code and
have
4 versions.
I have an idea about solving it but it seems heavy handed and
before
you switch-off is there any rational solution to the following?:
The nature of the environmental customisation involves a complex
CASE statement that uses the LIKE predicate to examine for and map 20-30
input patterns to an output group. The input values are not 'patterned'
identically and percents signs or underscores can appear in any of the
eight
character positions. The patterns don't 'convert' very easily to a user
format.
I opted for the following type of code construct:
A source member (MYCODE):
MACRO _mycode
when infldc like 'ABC%123' then 'Group1'
when infldc like '%XXXX' then 'Group2'
otherwise 'Groupz'
%
The inline code:
%include lib(mycode);
proc sql ;
Select date, inflda, infldb,
case
_mycode
end as groupid
from myfile
where date between x and y;
quit;
run;
The failure occurs at the point of the %include when the compiler
attempts to compile the partial case statement, presumably having seen the
embedded % sign , stops the MACRO _Mycode scan and presumably starts
looking
for another valid token.
My thought is to abandon the MACRO _mycode style and just assign
the
partial case statement to a macro variable using a %LET and then referring
to the macro variable instead of _mycode in the select clause.
Any thoughts or references from anybody about general management of
percent signs in the macro context plus a specific solution most welcome.
TIA,
Nigel
Nigel Greenwood
EDS UK
Systems Resource Management
UK Mainframe Hosting Services
Information Technology Outsourcing
External: 01253 335126
Internal: X65126
-----------------------------------------------------------------------
This document is strictly confidential and is intended only for use by the
addressee.
If you are not the intended recipient, any disclosure, copying,
distribution
or other
action taken in reliance of the information contained in this e-mail is
strictly prohibited.
Any views expressed by the sender of this message are not necessarily those
of the Department
for Work and Pensions.
If you have received this transmission in error, please use the reply
function to tell us
and then permanently delete what you have received.
Please note: Incoming and outgoing e-mail messages are routinely monitored
for compliance
with our policy on the use of electronic communications.
The original of this email was scanned for viruses by the Government Secure
Intranet (GSi) virus scanning service supplied exclusively by Energis in
partnership with MessageLabs.
On leaving the GSi this email was certified virus-free
___________________________________________________________________________
_
______________________________________________________
This e-mail may be privileged and/or confidential, and the sender does not
waive any related rights and obligations.
Any distribution, use or copying of this e-mail or the information it
contains by other than an intended recipient is unauthorized.
If you received this e-mail in error, please advise me (by return e-mail or
otherwise) immediately.
Ce courrier électronique est confidentiel et protégé. L'expéditeur ne
renonce pas aux droits et obligations qui s'y rapportent.
Toute diffusion, utilisation ou copie de ce message ou des renseignements
qu'il contient par une personne autre que le (les) destinataire(s)
désigné(s) est interdite.
Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser
immédiatement, par retour de courrier électronique ou par un autre moyen.
PLEASE NOTE: THE ABOVE MESSAGE WAS RECEIVED FROM THE INTERNET.
On entering the GSi, this email was scanned for viruses by the Government
Secure Intranet (GSi) virus scanning service supplied exclusively by
Energis
in partnership with MessageLabs.
Please see http://www.gsi.gov.uk/main/notices/information/gsi-003-2002.pdf
for further details.
In case of problems, please call your organisational IT helpdesk
-----------------------------------------------------------------------
This document is strictly confidential and is intended only for use by the
addressee.
If you are not the intended recipient, any disclosure, copying,
distribution or other
action taken in reliance of the information contained in this e-mail is
strictly prohibited.
Any views expressed by the sender of this message are not necessarily those
of the Department
for Work and Pensions.
If you have received this transmission in error, please use the reply
function to tell us
and then permanently delete what you have received.
Please note: Incoming and outgoing e-mail messages are routinely monitored
for compliance
with our policy on the use of electronic communications.
The original of this email was scanned for viruses by the Government Secure
Intranet (GSi) virus scanning service supplied exclusively by Energis in
partnership with MessageLabs.
On leaving the GSi this email was certified virus-free