| Date: | Thu, 14 Jan 2010 11:57:00 -0600 |
| Reply-To: | mpajoh@ODOT.ORG |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Masoud Pajoh <mpajoh@ODOT.ORG> |
| Subject: | Re: Macro question |
|
| In-Reply-To: | <1263488067.11231.1354654831@webmail.messagingengine.com> |
| Content-Type: | text/plain; charset="US-ASCII" |
|---|
Is this a related question?
In the following:
%let EndDate = 01Mar2010;
%let StartDate = 01Dec2009;
%let s="&Start."d;
%let e="&End."d;
%let test=%sysfunc(intck(d,&e.,&s.));
%put &test.;
Here is the log:
1 %let EndDate = 01Mar2010;
2 %let StartDate = 01Dec2009;
3 %let s="&StartDate."d;
SYMBOLGEN: Macro variable STARTDATE resolves to 01Dec2009
4 %let e="&EndDate."d;
SYMBOLGEN: Macro variable ENDDATE resolves to 01Mar2010
5 %let test=%sysfunc(intck(d,&e.,&s.));
SYMBOLGEN: Macro variable E resolves to "01Mar2010"d
SYMBOLGEN: Macro variable S resolves to "01Dec2009"d
WARNING: An argument to the function INTCK referenced by the %SYSFUNC or
%QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC
function execution. The result of the operations have been set to a
missing value.
6 %put &test.;
SYMBOLGEN: Macro variable TEST resolves to .
Thanks,
Masoud
Jack Hamilton <jfh@stanfordalumni.org>
Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
01/14/2010 10:54 AM
Please respond to
jfh@stanfordalumni.org
To
SAS-L@LISTSERV.UGA.EDU
cc
Subject
Re: Macro question
"&EndDate"d will work in a call to %SYSFUNC:
=====
1 %let EndDate = 01Feb2010;
2 %let NewDate = %sysfunc(intnx(month, "&EndDate."d, -1), date9.);
3 %put &NewDate.;
01JAN2010
=====
The documentation (for 9.1,
<
http://support.sas.com/onlinedoc/913/getDoc/en/mcrolref.hlp/z3514sysfunc.htm
>)
says:
Because %SYSFUNC is a macro function, you do not need to enclose
character
values in quotation marks as you do in DATA step functions. For
example, the
arguments to the OPEN function are enclosed in quotation marks when
the
function is used alone, but do not require quotation marks when used
within
%SYSFUNC.
I think that the documentation as written is incorrect. To me, "not
required" is not the same as "not allowed". In general, SAS does not
take the "everything that is not compulsory is forbidden" approach, but
in this case it appears that they do.
Note that it talks about character values, not numeric values. The
second argument to INTNX is numeric, not character, so it is not obvious
that quotes are forbidden there. And indeed, quotes, in the context of
a date constant, are allowed in this case.
Interestingly, a quoted hex character constant is not allowed for the
first, character, argument:
=====
4 %put %sysfunc(putc(month, $hex10.));
6D6F6E7468
5 %let EndDate = 01Feb2010;
6 %let NewDate = %sysfunc(intnx('6D6F6E7468'x, "&EndDate."d, -1),
date9.);
WARNING: An argument to the function INTNX referenced by the %SYSFUNC or
%QSYSFUNC macro
function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC
function execution. The
result of the operations have been set to a missing value.
7 %put &NewDate.;
.
=====
That syntax does work in the data step:
=====
20 data _null_;
21 newdate = intnx('6D6F6E7468'x, "&EndDate."d, -1);
22 put newdate=date9.;
23 run;
newdate=01JAN2010
=====
You can use a hex constant for the date value:
=====
30 %put %sysfunc(putn("01feb2010"d, hex8.));
00004776
31
32 %let NewDate = %sysfunc(intnx(month, 00004776x, -1), date9.);
33 %put &NewDate.;
01JAN2010
=====
You can use scientific notation:
=====
38 %put %sysfunc(putn("01feb2010"d, e12.));
1.82940E+04
39
40 %let NewDate = %sysfunc(intnx(month, 1.82940E+04, -1), date9.);
41 %put &NewDate.;
01JAN2010
=====
So what conclusion can we draw about what kinds of arguments are
allowed?
It appears that for numeric parameters you can use a number (in decimal,
hexadecimal, or scientific notation) or a date constant (and presumably
time and datetime constants as well).
For character parameters you can use only unquoted strings. You can't
use constants in hexadecimal notation.
On Wed, 13 Jan 2010 13:29 -0600, "Joe Matise" <snoopy369@GMAIL.COM>
wrote:
> First off, I believe SYSFUNC arguments are intended to be unquoted (no '
> "
> ). 'month' should be month (no quotes).
>
> Secondly, "&EndDate"d won't work in the SYSFUNC, as far as I can tell.
> You'll need to either pass it as a date value, or inside the sysfunc
> input
> it into a date value.
>
> Finally, you are recursively referenceing EndDate in the %let statement
-
> probably not good idea. It doesn't do any harm, but it makes it
> difficult
> to see the errors.
>
> This works, for example:
>
> %macro test( StartDate, EndDate);
> %let EndDate=%sysfunc(intnx('month',&EndDate,1));
> %let StartDate=01&StartDate.;
> %let where="&StartDate."d<=model<="&EndDate."d;
> %mend(test);
>
> %test( jan09, 17198);
>
> -Joe
>
>
>
> On Wed, Jan 13, 2010 at 12:53 PM, Masoud Pajoh <mpajoh@odot.org> wrote:
>
> > All:
> > The following is a fragment of a much larger macro.
> >
> > %macro test( StartDate, EndDate);
> > %let EndDate=%sysfunc(intnx('month',"&EndDate."d,1));
> > %let StartDate=01&StartDate.;
> > %let where="&StartDate."d<=model<="&EndDate."d;
> > %mend(test);
> >
> > %test( jan09, dec09);
> >
> > WHERE should resolve to "01jan09"d<=model<="01jan10"d
> > But, I get:
> >
> > WARNING: An argument to the function INTNX referenced by the %SYSFUNC
or
> > %QSYSFUNC macro function is out of range.
> >
> > What is wrong?
> >
> > Thanks,
> >
> > Masoud
> >
--
Brevis esse laboro, obscurus fio.
Jack Hamilton
Sacramento, California
jfh@alumni.stanford.org
|