Date: Fri, 28 Apr 2000 16:05:16 +0200
Reply-To: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Subject: Re: Current date (Autoexec)
Content-Type: text/plain
Fabrizio,
To me &SYSDATE is outdated. If not used with care it may cause the Y2K bug.
It returns the current date in the DATE7. format, thus without the century
number. INPUTting it into some numeric date variable causes it to be
interpreted as a date 100 years ago. Unless you have set the YEARCUTOFF
option appropriately, like in the following code, which you might include in
your AUTOEXEC.SAS file:
OPTIONS YearCutOff=1950;
%macro CURDATE(fmt);
%global curdate;
%let curdate=%sysfunc(PUTN("&sysdate"d, &fmt));
%mend CURDATE;
%CURDATE(date9.);
%PUT &curdate; %* to show;
But I like a more robust method, that always works correctly. It is based on
the TODAY() function, which always returns the number of days since 1 Jan
1960 and which always would cause a valid date as a result:
%macro CURDATE(fmt);
%global curdate;
%let curdate=%SYSFUNC(TODAY(),&fmt);
%mend CURDATE;
%CURDATE(date9.);
%PUT &curdate; %* to show;
Regards - Jim.
--
Y. Groeneveld, MSc IMRO TRAMARKO tel. +31 412 407 070
senior statistician, P.O. Box 1 fax. +31 412 407 080
head IT department 5350 AA BERGHEM IMRO TRAMARKO: a CRO
J.Groeneveld@ITGroups.com the Netherlands in clinical research
My computer allows me to be buggy, imperfect; my wife ......
> -----Original Message-----
> From: F a b r i z i o [SMTP:Fabrizio1@USA.NET]
> Sent: Friday, April 28, 2000 2:44 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Current date (Autoexec)
>
> Daniella Priscila Cruz - Estagiaria SAS wrote in message ...
> >Dear list,
> >
> > I would like to know how I can insert in my program a new obeservation
> >when I open the program.
> >
> > When I open my program I want to create in my variable a new observation
> >that have the current date.
> >
> > Can I configure anything in my autoexec.sas?
>
>
> Shortest might be this piece of code in your AUTOEXEC:
>
> LIBNAME libname your.library;
> PROC SQL;
> INSERT INTO libname.memname (date)
> VALUES ("&SYSDATE"D);
> QUIT;
> LIBNAME libname CLEAR;
>
> Any lowercase item is to be set to a value of your choice.
> You may even drop the LIBNAME statements if you
> decide to place your dataset in the SASUSER library.
> Only preparation to be done is: Make sure the dataset
> exists with at least the single 'date' variable.
>
> Brgds, Fabrizio
|