Date: Wed, 21 Jul 1999 08:59:24 -0700
Reply-To: "Lund, Pete" <Peter.Lund@CFC.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Lund, Pete" <Peter.Lund@CFC.WA.GOV>
Subject: Re: Macro Mystery
Content-Type: text/plain; charset="windows-1252"
Howard-
The problem is that the values of left, middle, and right remain quoted
(from the %bquote in the call to the macro). PROC FORMAT doesn't seem to
interpret the quoted quotes. With the logic in your macro to handle the
multiple formats you'll need to create a temporary macro variable to build
the output value and unquote it on the way out. The following small change
to your macro works for me:
%macro yrbyr(loyr,hiyr,left,middle,right);
%* Generate code like
x99 x00 x01
or
x99=y99 x00=y00 x01=y01
;
%do year4 = &LOYR %to &HIYR;
%let year = %substr(&YEAR4,3,2);
%let assign = &LEFT&YEAR;
%if %length(&MIDDLE) %then
%do;
%let assign = &assign&MIDDLE&YEAR;
%end;
%let assign = &assign&RIGHT;
%end;
%unquote(&assign)
%mend yrbyr;
As for the strange results with your MPRINT, I'm not even going to try and
guess.
HTH-
Pete Lund
WA State Caseload Forecast Council
515 15th Ave SE
Olympia, WA 98504-0962
(360) 902-0086 - voice
(360) 902-0084 - fax
peter.lund@cfc.wa.gov <mailto:peter.lund@cfc.wa.gov>
-----Original Message-----
From: Howard Schreier [mailto:Howard_Schreier@ITA.DOC.GOV]
Sent: Wednesday, July 21, 1999 8:28 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Macro Mystery
I'm definitely not a macro maven.
This came up in the course of some minor Y2K remediation. I want to get rid
of constructs like
value94-value98
representing annual time series in variable lists.
Here's my macro:
%macro yrbyr(loyr,hiyr,left,middle,right);
%* Generate code like
x99 x00 x01
or
x99=y99 x00=y00 x01=y01
;
%do year4 = &LOYR %to &HIYR;
%let year = %substr(&YEAR4,3,2);
&LEFT&YEAR%if %length(&MIDDLE)
%then %do;&MIDDLE&YEAR%end;&RIGHT %end;
%mend yrbyr;
Here's a test job:
proc format;
value $newnam
%yrbyr(1997,2001,%bquote('Old),%bquote('='New),%bquote('))
;
run;
The ugliness from the log is shown below. What's really strange,
to me at least, is the MPRINT output. The first two years generate
the expected character strings, the third does not, the fourth and
fifth are OK but all the letters have been upcased.
What is happening, and why?
TIA
From the SAS log:
ERROR: This range is repeated, or values overlap: '-'.
NOTE: Line generated by the macro variable "YEAR".
134 New
-
200
ERROR 200-322: The symbol is not recognized.
NOTE: Line generated by the macro variable "YEAR".
134 New
-
76
ERROR 76-322: Syntax error, statement will be ignored.
MPRINT(YRBYR): 'Old97'='New97' 'Old98'='New98' 'Old99'='99'
'OLD00'='NEW00'
'OLD01'='NEW01'
135 ;
NOTE: The previous statement has been deleted.
136 run;
NOTE: The SAS System stopped processing this step because of errors.